0
我想要使用下面的代碼來顯示一個意圖,如果記錄計數是=太大或大於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);
}
}
}
'NullPointError..'添加你的logcat ... –
哪一行是引發的'NullPointerException'? –
你是否實例化了你的mDbHelper?打開數據庫? – Barak