2013-11-18

java.lang.RuntimeException: Unable to instantiate service - IntentService

練習 IntentService 時發生奇怪的錯誤。
public class HelloIntentService extends IntentService {

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

  @Override
  protected void onHandleIntent(Intent intent) {
      // ...
  }

}
啟動 service 時發生錯誤。
java.lang.RuntimeException: Unable to instantiate service com.xxx.HelloIntentService: java.lang.InstantiationException: com.xxx.HelloIntentService
瞎子摸象後找到奇怪的原因,要實作沒有參數的 constructor(No-args Constructor)
public class HelloIntentService extends IntentService {

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

  @Override
  protected void onHandleIntent(Intent intent) {
      // ...
  }

}
---
---
---

沒有留言:

張貼留言