Chowdary102
Chowdary102

Reputation: 106

Using Popup menu giving ClassNotFound Exception

I am using popup menu in my app and it is crashing after on click, giving ClassNotFound Exception. I had used the following code

menu=(ImageView)findViewById(R.id.menu);
  menu.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View view) {
        // TODO Auto-generated method stub
        PopupMenu popupMenu = new PopupMenu(HTTTPGet.this, view);
        popupMenu.setOnMenuItemClickListener(HTTTPGet.this);
        popupMenu.inflate(R.menu.popupmenu);
        popupMenu.show();
    }
});

here is the onmenuitemclick method

@Override
public boolean onMenuItemClick(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {

case R.id.home:
    Intent home=new Intent(this,HTTTPGet.class);
    startActivity(home);
    return true;
case R.id.schedule:
    Intent schedule=new Intent(this,Schedule.class);
    startActivity(schedule);
    return true;
case R.id.manual:
    Intent manual=new Intent(this,Schedule.class);
    startActivity(manual);
    return true;
default:
return false;
}
}

after clicking on imageview app is getting crashed and the logcat is

    09-30 16:19:31.560: E/AndroidRuntime(6294): FATAL EXCEPTION: main
09-30 16:19:31.560: E/AndroidRuntime(6294): java.lang.NoClassDefFoundError: android.widget.PopupMenu
09-30 16:19:31.560: E/AndroidRuntime(6294):     at com.teapoyinfotech.cvv.HTTTPGet$1.onClick(HTTTPGet.java:99)
09-30 16:19:31.560: E/AndroidRuntime(6294):     at android.view.View.performClick(View.java:2538)
09-30 16:19:31.560: E/AndroidRuntime(6294):     at android.view.View$PerformClick.run(View.java:9152)
09-30 16:19:31.560: E/AndroidRuntime(6294):     at android.os.Handler.handleCallback(Handler.java:587)
09-30 16:19:31.560: E/AndroidRuntime(6294):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-30 16:19:31.560: E/AndroidRuntime(6294):     at android.os.Looper.loop(Looper.java:130)
09-30 16:19:31.560: E/AndroidRuntime(6294):     at android.app.ActivityThread.main(ActivityThread.java:3687)
09-30 16:19:31.560: E/AndroidRuntime(6294):     at java.lang.reflect.Method.invokeNative(Native Method)
09-30 16:19:31.560: E/AndroidRuntime(6294):     at java.lang.reflect.Method.invoke(Method.java:507)
09-30 16:19:31.560: E/AndroidRuntime(6294):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
09-30 16:19:31.560: E/AndroidRuntime(6294):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
09-30 16:19:31.560: E/AndroidRuntime(6294):     at dalvik.system.NativeStart.main(Native Method)

Does I need to add anything to above code?

Upvotes: 0

Views: 153

Answers (3)

Sergey Kapustin
Sergey Kapustin

Reputation: 11

PopupMenu was introduced in the API level 11

Looks like you are compiling your project with 11+, minumum API is less than 11, and launching on device with android version less than 11.

This might cause ClassNotFoundException

The decicions are as follow: 1) Increase your minimum API level to 11 in your AndroidManifest.xml (thus that makes it impossible to launch application on devices with android version less than 11 2) Use PopupMenu from android support v7 library (android.support.v7.widget.PopupMenu) In order to get this library, please refer to: http://developer.android.com/tools/support-library/setup.html

Hope one of this things will fit your needs

Upvotes: 1

Piyush
Piyush

Reputation: 18933

PopupMenu is available from Android API 11.

So just check your minimum SDK version in manifest file. And atleast you have to set minimum SDK version 11.

For more information read documents http://developer.android.com/reference/android/widget/PopupMenu.html

Upvotes: 1

M S Gadag
M S Gadag

Reputation: 2057

in spite of specifying only this give activityname.this while calling the intent in your onmenuitemclick method. hope it works

Upvotes: 0

Related Questions