我有一个我写的Android应用程序,它在我的手机上运行完美,还有许多其他用户手机来自在Play商店中下载的人。由于某种原因,应用程序部队仅在他的手机上自动关闭。这是他发给我的错误信息:
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
我不确定为什么它只是在他的手机上失败了。我朋友使用的手机是:HTC One S(ville)
答案 0 :(得分:1)
你应该像你一样在你的Activity中添加一个方法
boolean onItemClick(MenuItem item){
//..your code
return true;
}
然后,你的menu.xml应该是这样的
<menu>
<item .....android:onClick="onItemClick" />
</menu>