Null Pointer exception starting IntentService

有些话、适合烂在心里 提交于 2019-11-30 06:06:19

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!