Search code examples
javaandroidnoclassdeffounderrorpopupmenu

How do I fix NoClassDefFoundError in Android for android.widget.PopupMenu?


I am trying to create a popup menu and I keep getting java.lang.NoClassDefFoundError: android.widget.PopupMenu

    public void showPopup(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(R.menu.tweet_menu, popup.getMenu());
    popup.show();
}

I realize this error means that the class is found in the classpath at compile, but not at runtime, but I am having trouble figuring out why, as this is part of Android SDK. I am using the newest version of the SDK and I am developing/compiling in Netbeans.

Please help!


Solution

  • PopupMenu is available since Android API 11. So in order to use you need a device with at least Android 3.0. Please refer to the Android developers docs