[英]Throwing null pointerException in Timer.Schedule();
在下面的代碼中
t.schedule(timertask,d.getDate(),1000); 拋出NullPointer異常幫助我
目標:
我的基本目標是運行一個方法( 每次在固定間隔后 ),該方法將從我的android設備向Web服務 發送一些數據
Date d = new Date();
d.getDate();
timertask = new TimerTask() {
@Override
public void run() {
new Thread() {
public void run() {
try {
ProDialog = ProgressDialog.show(Home.this,
"Sending Data",
"Please wait while sending data...");
Looper.prepare();
sendLocation();
handler.sendEmptyMessage(0);
quit();
Looper.loop();
} catch (Exception e) {
ProDialog.dismiss();
}
}
public void quit() {
ProDialog.dismiss();
Looper.myLooper().quit();
}
}.start();
}
};
try {
t.schedule(timertask, d.getDate(), 1000);
} catch (Exception e) {
e.printStackTrace();
}
您需要初始化
Ť
第一。
更改
try {
t.schedule(timertask, d.getDate(), 1000);
} catch (Exception e) {
e.printStackTrace();
}
至
try
{
Timer t=new Timer();
t.schedule(timertask, d.getDate(), 1000);
}
catch (Exception e)
{
e.printStackTrace();
}
基本上NullPointerException
拋出要求的對象為null
。
NullPointerException
的原因
在此鏈接中更詳細地解釋什么是NullPointerException,我該如何解決?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.