Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionBarSherlock: getSupportMenuInflator() is undefined

I'm using ActionBarSherlock and trying to inflate my XML menu by using getSupportMenuInflator(), but it is giving an error:

the method getSupportMenuInflator() is undefined for the type ...

I'm unable to figure out why it's showing the error. Here is the code:

public void onCreateOptionsMenu(Menu menu) {
    getSupportMenuInflater().inflate(R.menu.activity_main, menu);
    ...
}

How do I fix it?

like image 499
user1951690 Avatar asked Dec 09 '22 18:12

user1951690


1 Answers

You need to use:

getSherlockActivity().getSupportMenuInflater().inflate(R.menu.activity_main, menu);

Since getSupportMenuInflater() is a method in SherlockActivity not SherlockFragment.

like image 152
Sam Avatar answered Dec 11 '22 08:12

Sam