0

I'm getting the exception: java.lang.NoClassDefFoundError when trying to build a DialogInterface.onClickListener that I use in an Activity when pressing an menu item.

this is the code:

public boolean onOptionsItemSelected( MenuItem item ) {
    DialogInterface.OnClickListener yesHandler =
            new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            finish();
        }
    };
}

When I press the menu item, that above code is invoked and the app crashes with this stack trace:

FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.syncpro.SyncMainActivity$1
at com.syncpro.SyncMainActivity.onOptionsItemSelected(SyncMainActivity.java:120)
at android.app.Activity.onMenuItemSelected(Activity.java:2205)
at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:774)
at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
at com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)
at com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)
at android.view.View$PerformClick.run(View.java:9152)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Force finishing activity com.syncpro/.SyncMainActivity

The error code line is SyncMainActivity.java:120 is exactly that one I pasted above (i.e. the creation of onClickListener).
I'm using API level 7.
Any idea about the cause and solution ?

5
  • where is the AlertDialog where you want to add the Listener? Jan 5, 2012 at 11:12
  • in that line no 120 what you are doing ? which is that line ?
    – Finder
    Jan 5, 2012 at 11:51
  • @Lalit; sorry for my innacuracy; more code here: [link] (pastebin.com/hNFwRTc8) The crash occurs already at the first OnClickListener creation. Jan 5, 2012 at 13:20
  • @Karthick: this is the line 120: DialogInterface.OnClickListener yesHandler = new DialogInterface.OnClickListener() {... Jan 5, 2012 at 13:21
  • @user1131951 you should look at the examples on net there are many already for AlertDialog. Jan 5, 2012 at 14:31

1 Answer 1

0
java.lang.NoClassDefFoundError: com.syncpro.SyncMainActivity

This is your error, it means that it cannot find your SyncMainActivity class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.