如果记录数等于或大于 5,我正在尝试使用以下代码显示一个意图,如果仪表板布局的第一个按钮上的记录数小于 5,则显示不同的意图。
但我不断收到邪恶的 NullPointError ............我是在正确的轨道上还是在风中飘扬,请帮助并指出我做错了什么......谢谢
private class DashboardClickListener implements OnClickListener {
// @Override
public void onClick(View v) {
Intent i = null;
switch (v.getId()) {
case R.id.dashboard_button_one:
if (mDbHelper.fetchAllNotes().getCount() >= 5){
i = new Intent(DashboardActivity.this, Demo.class);}
else if (mDbHelper.fetchAllNotes().getCount() < 5){
i = new Intent(DashboardActivity.this, one.class);}
break;
case R.id.dashboard_button_two:
i = new Intent(DashboardActivity.this, two.class);
break;
case R.id.dashboard_button_three:
i = new Intent(DashboardActivity.this, three.class);
break;
case R.id.dashboard_button_four:
i = new Intent(DashboardActivity.this, four.class);
break;
default:
break;
}
if(i != null) {
startActivity(i);
}
}
}