user1657178
user1657178

Reputation: 21

Trouble creating a main menu

I'm learning how to make android app, and below is the code I'm using to create a main menu. The problem is that it keeps saying "mainmenu cannot be resolved or is not a field."

package chapter.seven;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuInflater;

public class UserInterface extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_interface);
    }

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

}

Upvotes: 0

Views: 129

Answers (2)

Andy Res
Andy Res

Reputation: 16043

In addition to what Paul said, import the application resource file if the class is not in the same package as the app's declared package:

import chapter.seven.R;

Upvotes: 0

Paul
Paul

Reputation: 5223

  1. Make sure you actually have defined a mainmenu XML Resource file which contains a proper menu definition.
  2. Make sure there are no errors in your layouts and XML Resource files. This could prevent the R file from being generated correctly.
  3. Refresh / Clean the project

Upvotes: 1

Related Questions