yuni khoirunnisa
yuni khoirunnisa

Reputation: 11

getMenuInflater().inflate(R.menu.main, menu);main cannot be resolved or is not a field,

i want to make maps. when i will try for first i have problem. this is my problem.

this my code

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}    

in this code, i have problem

getMenuInflater().inflate(R.menu.main, menu);

the comment is main cannot be resolved or is not a field

Upvotes: 1

Views: 14477

Answers (2)

Yogesh Srivastava
Yogesh Srivastava

Reputation: 311

I faced same issue Just check your import for R. In my case it was.

import android.R;

Change it to

import your.application.packagename.R;

Upvotes: 0

You should have a menu.xml file in your res/menu folder (if you don't have any, make it), with a content like this:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item
        android:id="@+id/action_settings"
        android:title="YOUR_MENU_ITEM"
        app:showAsAction="never"/>
</menu>

Upvotes: 1

Related Questions