2 回答

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超7個(gè)贊
兩個(gè)最可能的問(wèn)題是 (1)eventScreen活動(dòng)未在您的 AndroidManifest.xml 中聲明或 (2)context變量為空。
要解決 (1),請(qǐng)將其添加到您的清單中:
<activity
android:name=".eventScreen"/>
要解決 (2),請(qǐng)使用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貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超3個(gè)贊
您的數(shù)據(jù)庫(kù)為空,因?yàn)槟鷽](méi)有對(duì)其進(jìn)行初始化。
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");
}
}
添加回答
舉報(bào)