Search code examples
androidactionbarsherlock

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?


Solution

  • You need to use:

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

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