Here is what LogCat says:
01-21 17:20:06.057: ERROR/AndroidRuntime(27463): java.lang.NoSuchMethodError: com.mohit.geo2do.activities.TasksList.showDialog
01-21 17:20:06.057: ERROR/AndroidRuntime(27463): at com.mohit.geo2do.activities.TasksList.onContextItemSelected(TasksList.java:190)
01-21 17:20:06.057: ERROR/AndroidRuntime(27463): at android.app.Activity.onMenuItemSelected(Activity.java:2183)
01-21 17:20:06.057: ERROR/AndroidRuntime(27463): at com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback.onMenuItemSelected(PhoneWindow.java:2785)
01-21 17:20:06.057: ERROR/AndroidRuntime(27463): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:140)
01-21 17:20:06.057: ERROR/AndroidRuntime(27463): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
01-21 17:20:06.057: ERROR/AndroidRuntime(27463): at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:129)
01-21 17:20:06.057: ERROR/AndroidRuntime(27463): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:898)
01-21 17:20:06.057: ERROR/AndroidRuntime(27463): at android.widget.Ada开发者_Python百科pterView.performItemClick(AdapterView.java:301)
01-21 17:20:06.057: ERROR/AndroidRuntime(27463): at android.widget.ListView.performItemClick(ListView.java:3626)
01-21 17:20:06.057: ERROR/AndroidRuntime(27463): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3600)
01-21 17:20:06.057: ERROR/AndroidRuntime(27463): at android.os.Handler.handleCallback(Handler.java:587)
01-21 17:20:06.057: ERROR/AndroidRuntime(27463): at android.os.Handler.dispatchMessage(Handler.java:92)
01-21 17:20:06.057: ERROR/AndroidRuntime(27463): at android.os.Looper.loop(Looper.java:123)
01-21 17:20:06.057: ERROR/AndroidRuntime(27463): at android.app.ActivityThread.main(ActivityThread.java:4363)
01-21 17:20:06.057: ERROR/AndroidRuntime(27463): at java.lang.reflect.Method.invokeNative(Native Method)
01-21 17:20:06.057: ERROR/AndroidRuntime(27463): at java.lang.reflect.Method.invoke(Method.java:521)
01-21 17:20:06.057: ERROR/AndroidRuntime(27463): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
01-21 17:20:06.057: ERROR/AndroidRuntime(27463): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
01-21 17:20:06.057: ERROR/AndroidRuntime(27463): at dalvik.system.NativeStart.main(Native Method)
I get an error at this phrase:
Bundle args = new Bundle();
args.putLong("id", ...); //Some arbitrary value
showDialog(DELETE_DIALOG, args);
I have an onPrepareDialog
method:
@Override
protected void onPrepareDialog(int id, Dialog dialog, Bundle args) {
switch (id) {
case DELETE_DIALOG:
AlertDialog log = (AlertDialog) dialog;
final Bundle bundle = args;
log.setButton(DialogInterface.BUTTON_POSITIVE, "Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
long id = bundle.getLong("id");
getContentResolver().delete(Tasks.CONTENT_URI, Tasks._ID + "=" + id, null);
adapter.notifyDataSetChanged();
}
});
break;
default:
break;
}
}
What could be the problem?
Generally that means the class you compiled against and the class you're running against are different versions. The method you are calling was accessible to your compiler but is not available to the JVM at runtime.
Only API8 and upper has it. lower than it only has Activity.showDialog (int).
精彩评论