Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected end of document (at android.view.MenuInflater.parseMenu)

Tags:

android

The code fails in this line when the app is launched (public boolean onCreateOptionsMenu(Menu menu)) as given by the logcat. Can anyone please point out Why so ???

@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)
like image 658
Jerry Wattre Avatar asked Jan 20 '14 12:01

Jerry Wattre


Video Answer


2 Answers

I had the same problem and was in XML, was putting a sub menu outside a <item> already closed /> Example:

<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>

Just remember to close the <item> after the sub menu. Simple, but sometimes happens.

like image 182
Marcos Paulo B. Avatar answered Oct 23 '22 06:10

Marcos Paulo B.


Unexpected end of document exception while inflating the menu implies that your menu (R.menu.official) does not have proper tags. You can check your xml from this website: http://www.xmlvalidation.com/

A sample menu file:

<?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>
like image 42
Arshad Mehmood Avatar answered Oct 23 '22 04:10

Arshad Mehmood