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?
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