Sam
Sam

Reputation: 29

Unreachable Code when using setContentView()

I have the following code:

public boolean onCreateOptionsMenu(Menu menu)
{
   menu.add(0, AUSRECHNEN_ID, Menu.NONE,"Umrechnen");
   return super.onCreateOptionsMenu(menu);
   setContentView(R.layout.main);
}

I get an "unreachable code" warning right next to the setContentView() method.

What am I doing wrong?

Upvotes: 0

Views: 1806

Answers (1)

Neil Knight
Neil Knight

Reputation: 48547

You are returning before you get to setContentView(R.layout.main);. Move your return after the setContentView if you want to use this method call.

public boolean onCreateOptionsMenu(Menu menu)
{
   menu.add(0, AUSRECHNEN_ID, Menu.NONE,"Umrechnen");
   // MOVED HERE SO IT CAN BE CALLED
   setContentView(R.layout.main);
   return super.onCreateOptionsMenu(menu);
}

Upvotes: 5

Related Questions