2 回答
TA贡献1895条经验 获得超7个赞
两个最可能的问题是 (1)eventScreen活动未在您的 AndroidManifest.xml 中声明或 (2)context变量为空。
要解决 (1),请将其添加到您的清单中:
<activity
android:name=".eventScreen"/>
要解决 (2),请使用ContextViewHolder 的 itemView 中的保证非空:
Context c = v.getContext();
Log.d(TAG, eventName.get(position) + " clicked");
Intent intent = new Intent(c, eventScreen.class);
intent.putExtra("name", eventName.get(position));
c.startActivity(intent);
TA贡献1946条经验 获得超3个赞
您的数据库为空,因为您没有对其进行初始化。
public class eventScreen extends AppCompatActivity {
public Database db; // db is NULL
public TextView name, location, date, website;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_event_screen);
name = findViewById(R.id.name);
location = findViewById(R.id.location);
date = findViewById(R.id.date);
website = findViewById(R.id.website);
// You should initialize your DataBase db here before calling loadInfo()
if (getIntent().hasExtra("name")) {
String eventName = getIntent().getStringExtra("name");
loadInfo(eventName);
}
else{
Toast.makeText(this, "No message", Toast.LENGTH_LONG).show();
}
}
public void loadInfo(String title){
// db is still NULL
// The crash happens here when you call --> db.getEventData() --> null.getEventData(title)
String [] info = db.getEventData(title);
name.setText("the ");
location.setText("the");
date.setText("the");
website.setText("the");
}
}
添加回答
举报