gpt4 book ai didi

android - 文档意外结束(在 android.view.MenuInflater.parseMenu)

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:00:08 29 4
gpt4 key购买 nike

当应用程序启动时,此行中的代码失败(public boolean onCreateOptionsMenu(Menu menu)),如 logcat 所示。任何人都可以指出为什么这样吗???

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.official, menu);
official_menu = menu.findItem(R.id.ac_official);
important_menu = menu.findItem(R.id.ac_important);
normal_menu = menu.findItem(R.id.ac_normal);
create_menu = menu.findItem(R.id.ac_create);
if(dp.getDesignation().equalsIgnoreCase("student")){
create_menu.setVisible(false);
}
profile_menu = menu.findItem(R.id.ac_profile);
return true;
}

洛格卡特

01-20 06:59:19.684: E/AndroidRuntime(996): FATAL EXCEPTION: main
01-20 06:59:19.684: E/AndroidRuntime(996): java.lang.RuntimeException: Unexpected end of document
01-20 06:59:19.684: E/AndroidRuntime(996): at android.view.MenuInflater.parseMenu(MenuInflater.java:197)
01-20 06:59:19.684: E/AndroidRuntime(996): at android.view.MenuInflater.inflate(MenuInflater.java:110)
01-20 06:59:19.684: E/AndroidRuntime(996): at com.notice.official.OfficialActivity.onCreateOptionsMenu(OfficialActivity.java:183)
01-20 06:59:19.684: E/AndroidRuntime(996): at android.app.Activity.onCreatePanelMenu(Activity.java:2504)
01-20 06:59:19.684: E/AndroidRuntime(996): at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:413)
01-20 06:59:19.684: E/AndroidRuntime(996): at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:775)
01-20 06:59:19.684: E/AndroidRuntime(996): at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:198)
01-20 06:59:19.684: E/AndroidRuntime(996): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
01-20 06:59:19.684: E/AndroidRuntime(996): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
01-20 06:59:19.684: E/AndroidRuntime(996): at android.view.Choreographer.doFrame(Choreographer.java:531)
01-20 06:59:19.684: E/AndroidRuntime(996): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
01-20 06:59:19.684: E/AndroidRuntime(996): at android.os.Handler.handleCallback(Handler.java:730)
01-20 06:59:19.684: E/AndroidRuntime(996): at android.os.Handler.dispatchMessage(Handler.java:92)
01-20 06:59:19.684: E/AndroidRuntime(996): at android.os.Looper.loop(Looper.java:137)
01-20 06:59:19.684: E/AndroidRuntime(996): at android.app.ActivityThread.main(ActivityThread.java:5103)
01-20 06:59:19.684: E/AndroidRuntime(996): at java.lang.reflect.Method.invokeNative(Native Method)
01-20 06:59:19.684: E/AndroidRuntime(996): at java.lang.reflect.Method.invoke(Method.java:525)
01-20 06:59:19.684: E/AndroidRuntime(996): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
01-20 06:59:19.684: E/AndroidRuntime(996): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-20 06:59:19.684: E/AndroidRuntime(996): at dalvik.system.NativeStart.main(Native Method)

最佳答案

我有同样的问题,在 XML 中,将子菜单放在 <item> 之外已经关闭/>示例:

<item
android:id="@+id/menu_map"
android:title="Map" />

<item
android:id="@+id/menu_options"
android:title="Options" />

<menu>
<item
android:id="@+id/menu_sync"
android:title="Sync" />
</menu>

请记住关闭 <item>在子菜单之后。很简单,但有时会发生。

关于android - 文档意外结束(在 android.view.MenuInflater.parseMenu),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21234338/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com