C Sharper
C Sharper

Reputation: 8626

Android menu creation issue

I am trying to create menu in android.

For that i made file in res/menu folder called menu.xml

I written following code in it:

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

          android:title="Bookmark" />  

</menu>

But its giving me error on following line:

<item android:id="@+id/menu_bookmark"

              android:title="Bookmark" />  

I am trying to implement this page on Login.java where in iam searching for this page as follows:

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu., menu);
        return true;
    }

But i am also not getting autosuggest for R.menu.menu (as if this page does not exists).

Please help me.

Error Text:

Description Resource    Path    Location    Type
Element type "item" must be followed by either attribute specifications, ">" or "/>".   menu.xml    /MessageReader/res/menu line 3  Android XML Format Problem
Syntax error on token ",", delete this token    Login.java  /MessageReader/src/com/example/messagereader    line 78 Java Problem
menu cannot be resolved or is not a field   Login.java  /MessageReader/src/com/example/messagereader    line 78 Java Problem

Location of my menu.xml file:

enter image description here

Upvotes: 0

Views: 715

Answers (1)

flx
flx

Reputation: 14226

Remove the blank at the end of the line. The xml parser does not like it very much.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/menu_bookmark"
          android:title="Bookmark"/>  
</menu>

And add the file name in your inflate call:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.menu, menu);
    return true;
}

Upvotes: 3

Related Questions