启动 IntentService时异常

今天写一个service继承自 IntentService,但是在启动的时候报错,报错内容:

 

今天写一个service继承自 IntentService,但是在启动的时候报错,报错内容:
04-27 16:45:40.289: W/dalvikvm(8792): threadid=1: thread exiting with uncaught exception (group=0x40015578)
04-27 16:45:40.390: E/AndroidRuntime(8792): FATAL EXCEPTION: main
04-27 16:45:40.390: E/AndroidRuntime(8792): java.lang.RuntimeException: Unable to instantiate service com.example.UpdateService1: java.lang.InstantiationException: com.example.UpdateService1
04-27 16:45:40.390: E/AndroidRuntime(8792): 	at android.app.ActivityThread.handleCreateService(ActivityThread.java:1933)
04-27 16:45:40.390: E/AndroidRuntime(8792): 	at android.app.ActivityThread.access$2500(ActivityThread.java:117)
04-27 16:45:40.390: E/AndroidRuntime(8792): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:989)
04-27 16:45:40.390: E/AndroidRuntime(8792): 	at android.os.Handler.dispatchMessage(Handler.java:99)
04-27 16:45:40.390: E/AndroidRuntime(8792): 	at android.os.Looper.loop(Looper.java:123)
04-27 16:45:40.390: E/AndroidRuntime(8792): 	at android.app.ActivityThread.main(ActivityThread.java:3687)
04-27 16:45:40.390: E/AndroidRuntime(8792): 	at java.lang.reflect.Method.invokeNative(Native Method)
04-27 16:45:40.390: E/AndroidRuntime(8792): 	at java.lang.reflect.Method.invoke(Method.java:507)
04-27 16:45:40.390: E/AndroidRuntime(8792): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
04-27 16:45:40.390: E/AndroidRuntime(8792): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
04-27 16:45:40.390: E/AndroidRuntime(8792): 	at dalvik.system.NativeStart.main(Native Method)
04-27 16:45:40.390: E/AndroidRuntime(8792): Caused by: java.lang.InstantiationException: com.example.UpdateService1
04-27 16:45:40.390: E/AndroidRuntime(8792): 	at java.lang.Class.newInstanceImpl(Native Method)
04-27 16:45:40.390: E/AndroidRuntime(8792): 	at java.lang.Class.newInstance(Class.java:1409)
04-27 16:45:40.390: E/AndroidRuntime(8792): 	at android.app.ActivityThread.handleCreateService(ActivityThread.java:1930)
04-27 16:45:40.390: E/AndroidRuntime(8792): 	... 10 more
04-27 16:46:07.199: I/Process(8792): Sending signal. PID: 8792 SIG: 9

 最后发现错误是在 构造函数方面

启动服务代码:

写道
startService(new Intent(this,UpdateService1.class));

 UpdateService1.class 继承 IntentService ,构造函数应该不带参数,结果带了参数,改成

	public UpdateService1() {
		super("SOME NAME");
	}

 

 

你可能感兴趣的:(IntentService)