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

时间:2014-01-20 12:36:21

标签: android

当应用程序启动时,代码在此行中失败(公共布尔值onCreateOptionsMenu(菜单菜单)),如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;
}

logcat的

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)

2 个答案:

答案 0 :(得分:5)

我遇到了同样的问题并且使用XML格式,在/>已经关闭<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>

请记住在子菜单后关闭{{1}}。 很简单,但有时会发生。

答案 1 :(得分:0)

在菜单膨胀时意外结束文档异常意味着您的菜单(R.menu.official)没有正确的标签。您可以在此网站上查看您的xml:http://www.xmlvalidation.com/

示例菜单文件:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:id="@+id/reset_count_menu"
    android:orderInCategory="101"
    android:showAsAction="never|collapseActionView"
    android:title="@string/reset_count"/>
<item
    android:id="@+id/count_type_menu"
    android:orderInCategory="102"
    android:showAsAction="never|collapseActionView"
    android:title="@string/count_forward_backward"/>
<item
    android:id="@+id/set_initial_count_menu"
    android:orderInCategory="103"
    android:showAsAction="never|collapseActionView"
    android:title="@string/set_initial_count"/>
<item
    android:id="@+id/set_counter_name_menu"
    android:orderInCategory="103"
    android:showAsAction="never|collapseActionView"
    android:title="@string/set_counter_name"/>

</menu>