Cannot resolve method setHasOptionsMenu in android Activity

byteC0de picture byteC0de · Feb 16, 2017 · Viewed 12.2k times · Source

I try to used setHasOptionsMenu(true); in my activity but i get an error. "cannot resolve method setHasOptionsMenu".

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.job_status_option_menu, menu);
    return super.onCreateOptionsMenu(menu);
}

Answer

Valentino S. picture Valentino S. · Feb 16, 2017

Try to remove setHasOptionMenu(true) from your onCreate() method, and change the onCreateOptionsMenu in this way:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.job_status_option_menu, menu);
    return true;
}