无法访问的代码?

时间:2013-03-11 21:10:52

标签: android android-layout android-button

我正在“尝试”制作Android应用。我试图让它成为当我点击一个按钮它将带我到另一个布局。我已经完成了其他所有事情,我很确定......除了这个之外还有0个错误。无法访问的代码。

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


Button bUtuube = (Button) findViewById(R.id.Utuube);
bUtuube.setOnClickListener(new View.OnClickListener() {

我在Button bUtuube = (Button) findViewById(R.id.Utuube)收到无法访问的代码错误。那是红线出现的地方。

干杯

2 个答案:

答案 0 :(得分:10)

return true;会导致您退出onCreateOptionsMenu方法并将控制权返回给调用者。所以编译器试图告诉你,在return语句之后没有办法获得代码。

答案 1 :(得分:2)

你错过了大括号:

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

} // < ----- missing

Button bUtuube = (Button) findViewById(R.id.Utuube);
bUtuube.setOnClickListener(new View.OnClickListener() {

从您显示的片段中无法分辨,但我假设YouTube按钮应该在onCreateOptionsMenu之外宣布,这似乎很可能。

相关问题