Vineet Kaushik Vineet Kaushik - 9 months ago 364
Java Question

android getMenuInflater() in a fragment subclass - cannot resolve method

I am trying to inflate a menu in a class that inherits the

Here is my
method -

public boolean OnCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(, menu) ;
return true;

This raises the following error:

Cannot resolve method 'getMenuInflater()'

I tried :

MenuInflater inflater = getActivity().getMenuInflater();

but then Android Studio highlights
in red and states:

Method does not override method from its superclass

I also tried to create a
method in the same class and have it return
new MenuInflater(this)

public MenuInflater getMenuInflater() {
return new MenuInflater(this);

but then the following error is thrown :

error: incompatible types: ForecastFragment cannot be converted to

error: method does not override or implement a method from a supertype

What do I do?

Answer Source

The signature of your onCreateOptionsMenu doesn't look right. Take a look at the docs here

Take a look this code

public void onCreate(Bundle savedInstanceState) {
    setHasOptionsMenu(true);//Make sure you have this line of code.

public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // TODO Add your menu entries here
    super.onCreateOptionsMenu(menu, inflater);