Couldn't resolve menu item onClick handler force close

1k views Asked by At

I have an android app that I wrote, that runs perfectley fine on my phone, and a whole lot of others user phones from people who downloaded in in the play store. For some reason the app force closes automatically just on his phone. Here is the error message he sent me:

android.view.InflateException: Couldn't resolve menu item onClick handler goToSearch in class android.view.ContextThemeWrapper
at android.view.MenuInflater$InflatedOnMenuItemClickListener.<init>(MenuInflater.java:202)
at android.view.MenuInflater$MenuState.setItem(MenuInflater.java:402)
at android.view.MenuInflater$MenuState.addItem(MenuInflater.java:436)
at android.view.MenuInflater.parseMenu(MenuInflater.java:173)
at android.view.MenuInflater.inflate(MenuInflater.java:95)
at com.example.freeBP.StatisticsPage.onCreateOptionsMenu(StatisticsPage.java:49)
at android.app.Activity.onCreatePanelMenu(Activity.java:2513)
at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:415)
at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:770)
at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:3179)
at android.os.Handler.handleCallback(Handler.java:608)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:5045)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoSuchMethodException: goToSearch [interface android.view.MenuItem]
at java.lang.Class.getConstructorOrMethod(Class.java:460)
at java.lang.Class.getMethod(Class.java:915)
at android.view.MenuInflater$InflatedOnMenuItemClickListener.<init>(MenuInflater.java:200)
... 18 more

I am not sure why its failing just on his phone. The phone my friend is using is: HTC One S (ville)

1

There are 1 answers

0
cui cui On

you should add a method in your Activity like this

boolean onItemClick(MenuItem item){
    //..your code
    return true;
}

And then ,your menu.xml should like this

<menu>
   <item .....android:onClick="onItemClick" />
</menu>