![](/img/trans.png)
[英]Android CountDownTimer Crash inside onFinish() to open a dialog
[英]Android CountDownTimer crash
我第一次使用CountDownTimer,但无法正常工作。 应用程序与此崩溃:
if(Game1.ifWorking == false) {
new CountDownTimer (30000, 1000) {
@Override
public void onFinish() {
Game1.ifWorking = false;
Game1.points = 0;
}
@Override
public void onTick(long millisUntilFinished) {
Game1.ifWorking = true;
crono.setText("Test" + millisUntilFinished / 1000);
}
}.start();
}
变量:
private static boolean ifWorking;
问题是什么?
编辑:
LogCat: http : //i.gyazo.com/b20c01f75d173edf3ee1a5a8569423ab.png
这样做告诉我错误如果应用仅在您自己的本地设备上,则可以使用LogCat。 即使当崩溃发生时设备没有连接到主机,连接设备并发出adb logcat命令也会下载整个logcat历史记录(至少在缓冲的程度上,这通常是很多日志数据) ,它不是无限的。)虽然我检查了CountDownTimer函数。
尝试这个
package com.tutorialspoint;
import java.lang.*;
public class BooleanDemo {
public static void main(String[] args) {
// create 2 Boolean objects b1, b2
Boolean b1, b2;
// create a boolean primitive res
boolean res;
// assign values to b1, b2
b1 = new Boolean(true);
b2 = new Boolean(false);
// assign the result of equals method on b1, b2 to res
res = b1.equals(b2);
String str = "b1:" +b1+ " and b2:" +b2+ " are equal is " + res;
// print res value
System.out.println( str );
}
}
Let us compile and run the above program, this will produce the following result:
b1:true and b2:false are equal is false
View crono
为null
。 初始化您的视图,然后调用setText
: crono.setText("Test" + millisUntilFinished / 1000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.