12

Possible Duplicate:
Android RuntimeException: Unable to instantiate the service

I am downloading my data using IntentService. My IntentService class definition is as follows:

public class DownloadService extends IntentService{
super("DownloadService");
@Override
    protected void onHandleIntent(Intent intent) {
        //download tasks...
    }
}

AndroidManifest.xml:

<appilcation>
<service android:name="DownloadService"/>
..
..
..
</application>

LauncherActivity.java:

@Override
public void onCreate(Bundle savedInstanceState) {
        ..
        ..
        ..
    Intent dwnldService = new Intent(this, DownloadService.class);
    startService(dwnldService);
}

But still I am getting this error:

08-13 08:57:09.416: E/AndroidRuntime(942): FATAL EXCEPTION: main
08-13 08:57:09.416: E/AndroidRuntime(942): java.lang.RuntimeException: Unable to instantiate service com.app.android.DowloadService: java.lang.InstantiationException: can't instantiate class com.app.android.DowloadService; no empty constructor
08-13 08:57:09.416: E/AndroidRuntime(942):  at android.app.ActivityThread.handleCreateService(ActivityThread.java:2237)
08-13 08:57:09.416: E/AndroidRuntime(942):  at android.app.ActivityThread.access$1600(ActivityThread.java:123)
08-13 08:57:09.416: E/AndroidRuntime(942):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
08-13 08:57:09.416: E/AndroidRuntime(942):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-13 08:57:09.416: E/AndroidRuntime(942):  at android.os.Looper.loop(Looper.java:137)
08-13 08:57:09.416: E/AndroidRuntime(942):  at android.app.ActivityThread.main(ActivityThread.java:4424)
08-13 08:57:09.416: E/AndroidRuntime(942):  at java.lang.reflect.Method.invokeNative(Native Method)
08-13 08:57:09.416: E/AndroidRuntime(942):  at java.lang.reflect.Method.invoke(Method.java:511)
08-13 08:57:09.416: E/AndroidRuntime(942):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-13 08:57:09.416: E/AndroidRuntime(942):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-13 08:57:09.416: E/AndroidRuntime(942):  at dalvik.system.NativeStart.main(Native Method)
08-13 08:57:09.416: E/AndroidRuntime(942): Caused by: java.lang.InstantiationException: can't instantiate class com.app.android.DowloadService; no empty constructor
08-13 08:57:09.416: E/AndroidRuntime(942):  at java.lang.Class.newInstanceImpl(Native Method)
08-13 08:57:09.416: E/AndroidRuntime(942):  at java.lang.Class.newInstance(Class.java:1319)
08-13 08:57:09.416: E/AndroidRuntime(942):  at android.app.ActivityThread.handleCreateService(ActivityThread.java:2234)
Community
  • 1
  • 1
Debopam Mitra
  • 1,842
  • 4
  • 27
  • 51
  • 1
    Does your manifest.xml really say `` or did you actually type it anew instead of just copying it into your question? – Till Helge Jan 11 '13 at 21:50

2 Answers2

33
public DownloadService() {
    super("Download service");
}

Try adding this to your service.

  • Just adding a space to the string! What difference is it going to make? – Debopam Mitra Aug 13 '12 at 09:23
  • 9
    I got it... My constructor included String name in the parameters. It shouldn't be there. And it doesn't matter if we give a space in parameter of super. – Debopam Mitra Aug 13 '12 at 09:41
  • 3
    Yes... Change the constructer from `public DownloadService(String name) {super(name);} to public DownloadService() { super("DownloadService");}` – Isham Sep 12 '13 at 09:30
2

Add default constructor with super("name") calling in your class

public DownloadService() {
    super("DownloadService");
 }
Atul Bhardwaj
  • 6,647
  • 5
  • 45
  • 63