嘿,我最近进入了 android 并制作了我的第一个应用程序,该应用程序旨在在用户按下开始按钮时启动 60 秒的运行计时器。该应用程序将内容视图设置为正常并显示 60,但是当我单击开始按钮时,它成功显示 59,然后应用程序崩溃。这是代码(它只有一个活动)
public class test1activity extends Activity
{
Thread countdown;
long f, pa, jee;
TextView ytvp;
String s;
TextView uyti;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ytvp = (TextView) findViewById(R.id.textView2);
uyti = (TextView) findViewById(R.id.tv2);
countdown = new Thread() {
public void run() {
jee = (System.currentTimeMillis()) / 1000;
while ((((System.currentTimeMillis()) / 1000) - jee) < 60)
{
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
f = ((System.currentTimeMillis()) / 1000) - jee;
pa = 60 - f;
s = String.valueOf(pa);
ytvp.setText(s);
}
}
}
};
}
public void whenclickstart(View view) {
countdown.start();
}