我已经制作了简单的倒数计时器应用程序,但是当我尝试使用 onDestroy 取消倒数计时器时,我得到了错误。我的 onDestroy 代码块:
@Override
public void onDestroy()
{
super.onDestroy();
countdowntimer.cancel();
}
和 LogCat 错误
12-18 19:16:06.383: E/AndroidRuntime(25512): FATAL EXCEPTION: main
12-18 19:16:06.383: E/AndroidRuntime(25512): java.lang.RuntimeException: Unable to destroy activity {com.android.SquirellMusic/com.android.SquirellMusic.SquirellMusicActivity}: java.lang.NullPointerException
12-18 19:16:06.383: E/AndroidRuntime(25512): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3106)
12-18 19:16:06.383: E/AndroidRuntime(25512): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3171)
12-18 19:16:06.383: E/AndroidRuntime(25512): at android.app.ActivityThread.access$2100(ActivityThread.java:132)
12-18 19:16:06.383: E/AndroidRuntime(25512): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1071)
12-18 19:16:06.383: E/AndroidRuntime(25512): at android.os.Handler.dispatchMessage(Handler.java:99)
12-18 19:16:06.383: E/AndroidRuntime(25512): at android.os.Looper.loop(Looper.java:150)
12-18 19:16:06.383: E/AndroidRuntime(25512): at android.app.ActivityThread.main(ActivityThread.java:4293)
12-18 19:16:06.383: E/AndroidRuntime(25512): at java.lang.reflect.Method.invokeNative(Native Method)
12-18 19:16:06.383: E/AndroidRuntime(25512): at java.lang.reflect.Method.invoke(Method.java:507)
12-18 19:16:06.383: E/AndroidRuntime(25512): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
12-18 19:16:06.383: E/AndroidRuntime(25512): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
12-18 19:16:06.383: E/AndroidRuntime(25512): at dalvik.system.NativeStart.main(Native Method)
12-18 19:16:06.383: E/AndroidRuntime(25512): Caused by: java.lang.NullPointerException
12-18 19:16:06.383: E/AndroidRuntime(25512): at com.android.SquirellMusic.SquirellMusicActivity.onDestroy(SquirellMusicActivity.java:364)
12-18 19:16:06.383: E/AndroidRuntime(25512): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3088)
任何帮助表示赞赏