なぜこのエラーが発生するのかわかりません。
エラーは次のとおりです。
06-09 11:09:13.875: E/AndroidRuntime(11336): FATAL EXCEPTION: main
06-09 11:09:13.875: E/AndroidRuntime(11336): java.lang.IllegalStateException: Could not execute method of the activity
06-09 11:09:13.875: E/AndroidRuntime(11336): at android.view.View$1.onClick(View.java:2144)
06-09 11:09:13.875: E/AndroidRuntime(11336): at android.view.View.performClick(View.java:2485)
06-09 11:09:13.875: E/AndroidRuntime(11336): at android.view.View$PerformClick.run(View.java:9080)
06-09 11:09:13.875: E/AndroidRuntime(11336): at android.os.Handler.handleCallback(Handler.java:587)
06-09 11:09:13.875: E/AndroidRuntime(11336): at android.os.Handler.dispatchMessage(Handler.java:92)
06-09 11:09:13.875: E/AndroidRuntime(11336): at android.os.Looper.loop(Looper.java:123)
06-09 11:09:13.875: E/AndroidRuntime(11336): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-09 11:09:13.875: E/AndroidRuntime(11336): at java.lang.reflect.Method.invokeNative(Native Method)
06-09 11:09:13.875: E/AndroidRuntime(11336): at java.lang.reflect.Method.invoke(Method.java:507)
06-09 11:09:13.875: E/AndroidRuntime(11336): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-09 11:09:13.875: E/AndroidRuntime(11336): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-09 11:09:13.875: E/AndroidRuntime(11336): at dalvik.system.NativeStart.main(Native Method)
06-09 11:09:13.875: E/AndroidRuntime(11336): Caused by: java.lang.reflect.InvocationTargetException
06-09 11:09:13.875: E/AndroidRuntime(11336): at java.lang.reflect.Method.invokeNative(Native Method)
06-09 11:09:13.875: E/AndroidRuntime(11336): at java.lang.reflect.Method.invoke(Method.java:507)
06-09 11:09:13.875: E/AndroidRuntime(11336): at android.view.View$1.onClick(View.java:2139)
06-09 11:09:13.875: E/AndroidRuntime(11336): ... 11 more
06-09 11:09:13.875: E/AndroidRuntime(11336): Caused by: java.lang.NullPointerException
06-09 11:09:13.875: E/AndroidRuntime(11336): at com.myapp.MainActivity.onClick(MainActivity.java:87)
06-09 11:09:13.875: E/AndroidRuntime(11336): ... 14 more
コードは次のとおりです。
public void onClick(View view) {
ListView l = getListView();
int position = l.getPositionForView(view);
cursor = ((SimpleCursorAdapter)l.getAdapter()).getCursor();
cursor.moveToPosition(position);
long id = cursor.getLong(cursor.getColumnIndex(MySQLiteHelper.COLUMN_ID));
String name = cursor.getString(cursor.getColumnIndex(MySQLiteHelper.COLUMN_NAME));
String day = cursor.getString(cursor.getColumnIndex(MySQLiteHelper.COLUMN_DAY));
switch (view.getId()) {
case R.id.button_day_edit:
Intent startDayEdit = new Intent(this, DayEditActivity.class);
startDayEdit.putExtra("dayID", id);
startDayEdit.putExtra("dayName", name);
startDayEdit.putExtra("dayDay", day);
this.startActivity(startDayEdit);
break;
case R.id.button_day_delete:
toast_deleted.setText(getString(R.string.toast_day_deleted));
toast_deleted.show();
datasource.deleteDay(id);
cursor = datasource.fetchAllDays();
dataAdapter.changeCursor(cursor);
break;
}
}
リスト項目内に 2 つのイメージビューがあり、1 つはその特定の項目の編集アクティビティを表示し、もう 1 つはそれを削除します。なんらかの理由で、この invocationtargetexception が発生していますが、その理由がわかりません。