调用WakefulIntentService.sendWakefulWork会导致runtimeexception

时间:2013-04-22 13:55:39

标签: android alarm wakelock

运行此代码时,它会给我一个异常RuntimeException。我还没有向WakeWork.class添加任何代码。有关为什么会爆炸的任何想法?

这是来自我的'接收方'警报。

   Intent i = new Intent(context, WakeWork.class);
   WakefulIntentService.sendWakefulWork(context, i);

的manifest.xml
<service android:name="com.PageP.WakeWork"></service>

WAKEWORK.CLASS

package com.PageP;

import android.content.Intent;

public class WakeWork extends WakefulIntentService {

public WakeWork(String name) {
    super(name);
    // TODO Auto-generated constructor stub
}

@Override
public void onCreate(){
    super.onCreate();
}

@Override
protected void doWakefulWork(Intent intent) {
    // TODO Auto-generated method stub

}
}

ERROR

    Thread [<1> main] (Suspended (exception RuntimeException))  
        ActivityThread.handleCreateService(ActivityThread$CreateServiceData) line: 2346 
        ActivityThread.access$1600(ActivityThread, ActivityThread$CreateServiceData) line: 126  
        ActivityThread$H.handleMessage(Message) line: 1221  
        ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
        Looper.loop() line: 137 
        ActivityThread.main(String[]) line: 4560    
        Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
        Method.invoke(Object, Object...) line: 511  
        ZygoteInit$MethodAndArgsCaller.run() line: 784  
        ZygoteInit.main(String[]) line: 551 
        NativeStart.main(String[]) line: not available [native method]  

LONGCAT

04-22 10:32:04.127:W / AsyncTask(9004):com.PageP.GrabURL.doInBackground(GrabURL.java:36) 04-22 10:32:04.127:W / AsyncTask(9004):at com.PageP.GrabURL.doInBackground(GrabURL.java:1) 04-22 10:32:19.080:E / AndroidRuntime(9004):java.lang.RuntimeException:无法实例化服务com.PageP.WakeWork:java.lang.InstantiationException:无法实例化类com.PageP.WakeWork;没有空的构造函数 04-22 10:32:19.080:E / AndroidRuntime(9004):引起:java.lang.InstantiationException:无法实例化类com.PageP.WakeWork;没有空构造函数

1 个答案:

答案 0 :(得分:0)

变化:

public WakeWork(String name) {
    super(name);
    // TODO Auto-generated constructor stub
}

为:

public WakeWork() {
    super("George");
}

(随意替换名称中的其他值)

当堆栈跟踪向您显示时,Android无法实例化您的服务,因为没有零参数的公共构造函数,这就是上面修复的地址。