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

How do I fix NoClassDefFoundError in android.widget.PopupMenu in Android?… here is a solution to the problem.

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

I’m trying to create a pop-up menu, but 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 that this error means that the class was found in the classpath at compile time, but not at runtime, but I can’t figure out why because it’s part of the Android SDK. I’m using the latest version of the SDK and I’m using Netbeans for dev/compile.

Please help!

Solution

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

Related Problems and Solutions