Hervé
Hervé

Reputation: 75

How to solve the "menu cannot be resolved or is not a field" error

I got the following issue with my menu

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

The file main_menu.xml was indeed created in the res/menu directory:

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

Eclipse couldn't resolve R.menu and generated the following error:

menu cannot be resolved or is not a field

Upvotes: 0

Views: 3966

Answers (1)

Herv&#233;
Herv&#233;

Reputation: 75

I spent hours googling and browsing StackOverflow. I simply fixed my issue by removing the R.java file in the "gen" directory. It forced Eclipse to regenerate it and R.menu got resolved.

I hope it will help others.

Upvotes: 2

Related Questions