开发者

Unreachable Code when using setContentView()

开发者 https://www.devze.com 2023-02-06 05:11 出处:网络
I have the following code: public boolean onCreateOptionsMenu(Menu menu) { menu.add(0, AUSRECHNEN_ID, Menu.NONE,\"Umrechnen\");

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

精彩评论

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