If you realize you have two return
,
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return super.onCreateOptionsMenu(menu); //primer return.
MenuInflater inflater = getMenuInflater();//Aqui se lanza el error Unreachable Statement
inflater.inflate(R.menu.game_menu,menu);
return true; //segundo return.
}
the first one will cause you to have a null menu since it does not inflate the menu at any time:
return super.onCreateOptionsMenu(menu);
You can simply return true
, after the inflater, "inflates" the layout using the inflate()
method:
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.game_menu, menu);
return true;
}
MenuInflater Instance the .xml of the menu in objects Menu .