当我试图在按钮中添加Start和Cancel时,出现此错误。 我看着计时器的文件,但我没有看到任何 “错误:非静态方法start()方法不能从静态上下文中引用”非静态方法start()不能从静态上下文中引用
public int number;
public TextView textfield;
Button buton;
int x = 1;
Boolean y = false;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reading);
new CountDownTimer(100000, 1000) {
public void onTick(long millisUntilFinished) {
textfield.setText("Time: " + millisUntilFinished/1000);
}
public void onFinish() {
textfield.setText("Time is up");
}
}.start();
textfield=(TextView)findViewById(R.id.Zamanlayici);
buton=(Button)findViewById(R.id.Click);
buton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//My Error is in there :(
if (y) {
CountDownTimer.start();
y= true;
}
else {
y = false;
CountDownTimer.cancel();
}
}
});
}
}
当地varriable定时器从内部类访问;需要最终删除 – Thorin
非常感谢你 – Thorin