Null Pointer exception starting IntentService

后端 未结 2 2003
南笙
南笙 2020-12-30 01:06

I\'ve got an IntentService that I\'m trying to start. When I do, it spits out this:

java.lang.RuntimeException: Unable to start service com.pec.testapp.servi         


        
相关标签:
2条回答
  • 2020-12-30 01:17

    If you're going to override onCreate() in your IntentService, then make sure you call super.onCreate() in it. That seems to quite likely be your problem.

    0 讨论(0)
  • 2020-12-30 01:33

    Not sure if it is the same problem, but I was using an intentService also, and I was having trouble using

    context = getApplicationContext();
    

    or context = getBaseContext(); I wasn't overriding onCreate so the previous solution may be the solution for you, I was working inside "onHandleIntent"

    I would get an immediate exception with the first, and a exception later when I tried using the 2nd.

    I ended up realizing that the Intentservice is itself a subclass of Context, so I substituted "this" wherever I needed an instance of "Context".

    This solved my problem.

    0 讨论(0)
提交回复
热议问题