【问题标题】:IntentService RuntimeException [duplicate]IntentService RuntimeException [重复]
【发布时间】:2011-12-15 15:47:28
【问题描述】:

可能重复:
Android RuntimeException: Unable to instantiate the service

问题:启动IntentService 会生成RuntimeException

我一无所知。如果您需要更多信息,请询问。日志:

D/dalvikvm( 6839): newInstance failed: no <init>()
D/AndroidRuntime( 6839): Shutting down VM
W/dalvikvm( 6839): threadid=1: thread exiting with uncaught exception (group=0x40015560)
E/AndroidRuntime( 6839): FATAL EXCEPTION: main
E/AndroidRuntime( 6839): java.lang.RuntimeException: Unable to instantiate service org.xyz.android.service.MyService: java.lang.InstantiationException: org.xyz.android.service.MyService
E/AndroidRuntime( 6839):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:1929)
E/AndroidRuntime( 6839):    at android.app.ActivityThread.access$2500(ActivityThread.java:117)
E/AndroidRuntime( 6839):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:985)
E/AndroidRuntime( 6839):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 6839):    at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime( 6839):    at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime( 6839):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 6839):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 6839):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 6839):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 6839):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 6839): Caused by: java.lang.InstantiationException: org.xyz.android.service.MyService
E/AndroidRuntime( 6839):    at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime( 6839):    at java.lang.Class.newInstance(Class.java:1409)
E/AndroidRuntime( 6839):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:1926)
E/AndroidRuntime( 6839):    ... 10 more

此代码调用服务(从ContentProvider 调用):

Intent i = new Intent(
        getContext(),
        MyService.class);
    i.putStringArrayListExtra(EXTRA_MISSING, missingMonths);
    i.putExtra(EXTRA_URI, uri);
    i.putExtra(EXTRA_START, startTime);
    i.putExtra(EXTRA_END, endTime);
    getContext().startService(i);

这是IntentService相关的代码块(只有两种方法。当然除了asynctask本身):

public MyService(String name) {
    super("MyService");
}

@Override
protected void onHandleIntent(Intent intent) {
        // ... do stuff
        new DownloaderTask().execute(missingMonths);
}

【问题讨论】:

  • 你在清单中描述过吗?

标签: android android-contentprovider runtimeexception intentservice


【解决方案1】:

您似乎缺少零参数公共构造函数。从您当前的构造函数中删除String name(因为无论如何您都没有使用它),您应该很高兴。

【讨论】:

  • 谢谢,我完全错过了。
  • 你能具体说明原因吗?因为它在那里默认了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-30
  • 1970-01-01
  • 2011-05-13
相关资源
最近更新 更多