0

When this code is run, it gives me a exception RuntimeException. I have yet to add any code to the WakeWork.class. Any thoughts on why this is bombing out?

THIS IS CALLED FROM MY 'ON RECEIVER' ALARM.

   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: Unable to instantiate service com.PageP.WakeWork: java.lang.InstantiationException: can't instantiate class com.PageP.WakeWork; no empty constructor 04-22 10:32:19.080: E/AndroidRuntime(9004): Caused by: java.lang.InstantiationException: can't instantiate class com.PageP.WakeWork; no empty constructor

iBoston
  • 69
  • 1
  • 9
  • Please post the entire stack trace. – CommonsWare Apr 22 '13 at 14:08
  • I am new to eclipse. How do i get to it where i can copy/paste it. – iBoston Apr 22 '13 at 14:17
  • I believe i posted it.... – iBoston Apr 22 '13 at 14:24
  • That is Eclipse catching the exception. Proceed past this point, then in the LogCat view, you will see the full stack trace, and can highlight lines and press Ctrl-C to copy them to the clipboard (Windows/Linux -- whatever the equivalent key sequence is for OS X). My guess is that your service is not registered in your manifest. – CommonsWare Apr 22 '13 at 14:26
  • You can see above where i show the manifest entry. Is that entry not correct? Okay, let me try the getting for stack trace info... – iBoston Apr 22 '13 at 14:31
  • If that element is in the correct place in the manifest file, it should be fine. I am merely guessing based upon the limited information supplied via your Eclipse quasi-trace. The full stack trace hopefully will be much more informative. – CommonsWare Apr 22 '13 at 14:32
  • Okay, i believe i posted what you were asking for... – iBoston Apr 22 '13 at 14:35

1 Answers1

0

Change:

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

to:

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

(feel free to substitute in some other value for the name)

As the stack trace shows you, Android cannot instantiate your service because there is no zero-argument public constructor, which is what the above fix addresses.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thank YOU! This is my first android app, and learning the android nuances is proving challenging... – iBoston Apr 22 '13 at 15:03
  • @user2250168: `IntentService` (and, by extension, `WakefulIntentService`) is different from most Android components. Normally, we *don't* implement a constructor and inherit a suitable zero-argument public constructor. For whatever reason, the author of `IntentService` required us to jump through this hoop of defining our own public zero-argument constructor. – CommonsWare Apr 22 '13 at 15:06
  • Are you allowed to display an activity when in doWakefulWork ? – iBoston Apr 22 '13 at 15:27
  • @user2250168: If by "allowed" you mean "is it technically possible", then yes. If by "allowed" you mean "will users be happy with this, or will they threaten me with physical harm", popping up an activity out of the middle of nowhere is likely to land on the "physical harm" side. You don't know what the user is doing in the foreground at the time. Usually, you would display a `Notification` from an `IntentService`. – CommonsWare Apr 22 '13 at 15:41
  • You've got a sense of humor.. I like that.. It seems to be crashing when ever i reference an activity.. that is why i was asking. I have safe guards in place for that.. My alarm is firing whether or not the user is actively using the app. If they are, I then launch an activity. But, in that attempt, i get a crash. The only difference is this code is now launched within the doWakefulWork function. – iBoston Apr 22 '13 at 15:52
  • @user2250168: I have never tried calling `startActivity()` from `doWakefulWork()`, though I am unaware of any particular problems. This sounds like a new StackOverflow question, where you can post your code and your stack trace. – CommonsWare Apr 22 '13 at 15:54