0

我创建了一个在三星 Galaxy ace 设备中完美运行的 android 应用程序。但是当我在 HTC Desire V 上运行相同的程序时,它给出了 FATAL EXCEPTION。注意:三星设备是 3.5 英寸屏幕设备,而 HTC 是 4 英寸设备。logcat中显示的错误如下:

FATAL EXCEPTION: main
java.lang.RuntimeException: Expecting menu, got ScrollView
at android.view.MenuInflater.parseMenu(MenuInflater.java:128)
at android.view.MenuInflater.inflate(MenuInflater.java:95)
at com.pixel.hp.activity.HandpumpActivity.onCreateOptionsMenu(HandpumpActivity.java:1476)
at android.app.Activity.onCreatePanelMenu(Activity.java:2508)
at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:407)
at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:762)
at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:3083)
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:4987)
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)

是因为屏幕尺寸变化还是其他原因?对此的任何想法都会非常有帮助。

我在以下方法中遇到错误(第二行是 HandpumpActivity.java:1476):

   public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_handpump, menu);
    return true;
}
4

1 回答 1

2

Make sure your activity_handpump.xml only contains <menu>, <item> or <group> elements. <ScrollView> should not be in activity_handpump.xml as per the Android documentation.

The only explanation on how it is working on Galaxy Ace that I could think of is that you are having different Layouts for menus loaded for different screen sizes (Ace is mdpi while Desire is hdpi)

于 2012-11-07T09:06:45.280 回答