Android – XML problem in the basic menu example

androidmenuxml

I am trying to create an app with some menus, an I am following the basic example available in the official android site:

http://developer.android.com/guide/topics/ui/menus.html

My problems appear when I define the menu in the XML. After creating the folder res/menu and creating the menu_option.xml file from eclipse…. The project (in general) gives an error that can be read from the Problems tab:

 
Unparsed aapt error(s)! Check the console for output
Android Packaging Problem

So, changing to the Console tab to get more information about the problem, this can be read:

 
[2010-06-02 11:35:54 - TestAudio] Error in an XML file: aborting build.
[2010-06-02 11:35:54 - TestAudio] W/ResourceType(11566): Bad XML block: header size 63327 or total size -144759824 is larger than data size 0
[2010-06-02 11:35:54 - TestAudio] /home/User/workspace/TestAudio/res/menu/options_menu.xml:1: error: Error parsing XML: no element found

The strange thing is that eclipse recognizes the menu items that I've defined in the XML,I can reference them in the code with no problems and my main activity builds. (and the rest of the files too).

Could it be that when eclipse creates a file, for some reason, the Android SDK has problems to read it, or something similar??

The XML code is exactly the same as the one in the example, so I don't really know what is happening. The code in options_menu.xml is this:

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/new_game"
          android:title="New Game" />
    <item android:id="@+id/quit"
          android:title="Quit" />
</menu>

Thanks in advance for your help!

Best Solution

Judging by the position of the error, and assuming you simply copy/pasted the XML from the example, you may be missing the XML declaration which should be on the first line of each XML file for it to be considered well-formed:

<?xml version="1.0" encoding="UTF-8"?>

Alternatively, you could try a clean build of the project to see if the error goes away