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

当app启动时(公共布尔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)

我有同样的问题,并在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> 。 很简单,但有时会发生。


文档异常意外结束时,菜单膨胀意味着您的菜单(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>
链接地址: http://www.djcxy.com/p/18731.html

上一篇: Unexpected end of document (at android.view.MenuInflater.parseMenu)

下一篇: angular.js $scope.$broadcast, $scope.$emit, $rootScope.$broadcast what to use?