我试图在我的应用程序中每分钟执行一次任务,我使用以下相同。代码位于 onCreate 方法中:
mTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
PageTask();// The task I want to exceute every 1 minute.
}
}, 0, REFRESH_TIME);
我在课堂上声明以下内容:
Timer mTimer = null;
long REFRESH_TIME = 10000;
但是,当我运行程序时,我在mTimer.scheduleAtFixedRate(new TimerTask()
我在某个地方出错了吗?
原木猫:
07-29 15:57:28.906: E/AndroidRuntime(15415): at com.Geet.CustomizedListView.onCreate(CustomizedListView.java:93)
07-29 16:01:16.179: E/AndroidRuntime(15748): FATAL EXCEPTION: main
07-29 16:01:16.179: E/AndroidRuntime(15748): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Geet/com.Geet.CustomizedListView}: java.lang.NullPointerException
07-29 16:01:16.179: E/AndroidRuntime(15748): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
07-29 16:01:16.179: E/AndroidRuntime(15748): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
07-29 16:01:16.179: E/AndroidRuntime(15748): at android.app.ActivityThread.access$600(ActivityThread.java:140)
07-29 16:01:16.179: E/AndroidRuntime(15748): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
07-29 16:01:16.179: E/AndroidRuntime(15748): at android.os.Handler.dispatchMessage(Handler.java:99)
07-29 16:01:16.179: E/AndroidRuntime(15748): at android.os.Looper.loop(Looper.java:137)
07-29 16:01:16.179: E/AndroidRuntime(15748): at android.app.ActivityThread.main(ActivityThread.java:4895)
07-29 16:01:16.179: E/AndroidRuntime(15748): at java.lang.reflect.Method.invokeNative(Native Method)
07-29 16:01:16.179: E/AndroidRuntime(15748): at java.lang.reflect.Method.invoke(Method.java:511)
07-29 16:01:16.179: E/AndroidRuntime(15748): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
07-29 16:01:16.179: E/AndroidRuntime(15748): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
07-29 16:01:16.179: E/AndroidRuntime(15748): at dalvik.system.NativeStart.main(Native Method)
07-29 16:01:16.179: E/AndroidRuntime(15748): Caused by: java.lang.NullPointerException
07-29 16:01:16.179: E/AndroidRuntime(15748): at com.Geet.CustomizedListView.onCreate(CustomizedListView.java:94)
07-29 16:01:16.179: E/AndroidRuntime(15748): at android.app.Activity.performCreate(Activity.java:5163)
07-29 16:01:16.179: E/AndroidRuntime(15748): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
07-29 16:01:16.179: E/AndroidRuntime(15748): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
07-29 16:01:16.179: E/AndroidRuntime(15748): ... 11 more