[英]unreachable code, counter = 0
package com.thenewboston.jordy;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Startingpoint extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_startingpoint);
}
int counter;
Button add, sub;
TextView display;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.startingpoint, menu);
return true;
counter = 0;
add = (Button) findViewById(R.id.BAdd);
sub = (Button) findViewById(R.id.Bsub);
display = (TextView) findViewById(R.id.tvDisplay);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter++;
display.setText("Your total is " + counter);
}
});
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
counter--;
display.setText("Your total is " + counter);
}
});
}
}
你好,我刚刚开始按照教程制作带有eclips的android应用程序。 现在,我在“ counter = 0”行中得到此错误无法到达的代码,我认为它必须在“ return true”行中进行某些操作,因为当我删除该错误已消失后,我又得到了其他错误:s,有人知道这是什么问题吗?
提前致谢
返回后的任何代码将永远不会执行。 因此,您将获得无法访问的代码。
将return放在方法的末尾
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.startingpoint, menu);
counter = 0;
...
return true;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.