开发者

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 setContentVie开发者_运维问答w() method.

What am I doing wrong?


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜