在Timer.Schedule()中抛出null pointerException;

5 java multithreading android timer timertask

在以下代码中
t.schedule(timertask,d.getDate(),1000); 抛出 NullPointer异常 帮助我

目标:
我的基本目标是运行一个方法(每次在一个固定的时间间隔后),将一些数据从我的Android设备发送webservice

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();
}
Run Code Online (Sandbox Code Playgroud)

Vip*_*hah 5

你需要初始化你的

Ť

第一.

更改

try {
        t.schedule(timertask, d.getDate(), 1000);
    } catch (Exception e) {
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

try 
 {
    Timer t=new Timer();
    t.schedule(timertask, d.getDate(), 1000);
 } 
catch (Exception e) 
 {
   e.printStackTrace();
 }
Run Code Online (Sandbox Code Playgroud)