今天本打算写一个IntentService的小例子,但是报错了。
04-03 18:19:53.849: W/dalvikvm(12857): threadid=1: thread exiting with uncaught exception (group=0x40015568)
04-03 18:19:53.849: E/AndroidRuntime(12857): FATAL EXCEPTION: main
04-03 18:19:53.849: E/AndroidRuntime(12857): java.lang.RuntimeException: Unable to start service com.paad.services.MyIntentService@4050f420 with Intent { cmp=com.paad.services/.MyIntentService }: java.lang.NullPointerException
04-03 18:19:53.849: E/AndroidRuntime(12857): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2069)
04-03 18:19:53.849: E/AndroidRuntime(12857): at android.app.ActivityThread.access$2800(ActivityThread.java:117)
04-03 18:19:53.849: E/AndroidRuntime(12857): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:994)
04-03 18:19:53.849: E/AndroidRuntime(12857): at android.os.Handler.dispatchMessage(Handler.java:99)
04-03 18:19:53.849: E/AndroidRuntime(12857): at android.os.Looper.loop(Looper.java:130)
04-03 18:19:53.849: E/AndroidRuntime(12857): at android.app.ActivityThread.main(ActivityThread.java:3703)
04-03 18:19:53.849: E/AndroidRuntime(12857): at java.lang.reflect.Method.invokeNative(Native Method)
04-03 18:19:53.849: E/AndroidRuntime(12857): at java.lang.reflect.Method.invoke(Method.java:507)
04-03 18:19:53.849: E/AndroidRuntime(12857): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
04-03 18:19:53.849: E/AndroidRuntime(12857): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
04-03 18:19:53.849: E/AndroidRuntime(12857): at dalvik.system.NativeStart.main(Native Method)
04-03 18:19:53.849: E/AndroidRuntime(12857): Caused by: java.lang.NullPointerException
04-03 18:19:53.849: E/AndroidRuntime(12857): at android.app.IntentService.onStart(IntentService.java:110)
04-03 18:19:53.849: E/AndroidRuntime(12857): at android.app.IntentService.onStartCommand(IntentService.java:118)
04-03 18:19:53.849: E/AndroidRuntime(12857): at com.paad.services.MyIntentService.onStartCommand(MyIntentService.java:30)
04-03 18:19:53.849: E/AndroidRuntime(12857): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2056)
04-03 18:19:53.849: E/AndroidRuntime(12857): ... 10 more
各种查资料,后来在StackOverFlow上面找到了答案。
http://stackoverflow.com/questions/7165215/null-pointer-exception-starting-intentservice
原来在onCreate里面没有调用super.onCreate。