【发布时间】:2012-05-30 16:52:06
【问题描述】:
我在 oncreate() 中有一个计时器,例如:
final Timer timer1 = new Timer();
timer1.schedule(new TimerTask() {
public void run() {
sendSMS();
}
}, 20000);
sendSMS() 方法如下:
private void sendSMS(){
float test2;
test2 = reallocation.getAccuracy(); //-> This is the line where logcat says.... NullPointerException
....
}
logcat 说:
05-30 18:32:26.962: W/dalvikvm(741): threadid=9: thread exiting with uncaught exception (group=0x4001d5a0)
05-30 18:32:26.972: E/AndroidRuntime(741): FATAL EXCEPTION: Timer-0
05-30 18:32:26.972: E/AndroidRuntime(741): java.lang.NullPointerException
05-30 18:32:26.972: E/AndroidRuntime(741): at com.eljoom.df.ActionGPS.sendSMS(ActionGPS.java:280)
在网上搜索之后,我相信我需要一个计时器处理程序......但我不知道如何实现它。
有人可以让我走上正轨吗?!
【问题讨论】:
-
你的重新分配数据类型是什么,你初始化了吗?
-
我将重新分配设置为 Location: Location reallocation=null;
-
那么您刚刚回答了您的问题,正如 assylias 所说,重新分配为空。你不能调用 reallocation.getAccuracy() 因为 ... reallocation 是 null :)。
标签: java android handler fatal-error