Rodin10 Rodin10 - 1 year ago 154
Android Question

java.lang.NullPointerException IntentService

I'm trying to start a service in a different app that's installed on the device. I get a NullPointerException when using startService

public void notConnected(){
Log.i(TAG,"no connection... reconnecting.");
Intent reset = new Intent("com.famoco.intent.action.TOGGLE_DATA");
Log.i(TAG,"calling " + reset.getAction());
Log.i(TAG,"couldn't start service");

and this is error log

E/AndroidRuntime: FATAL EXCEPTION: IntentService[MyAppCommService]
Process: com.myapppackage.MyApp, PID: 8583
at android.content.ContextWrapper.startService(
at com.myapppackage.MyApplocation.activity.MyAppActivity.notConnected(
at com.myapppackage.MyApplocation.api.MyAppApi.submitClock(
at com.myapppackage.MyApplocation.service.MyAppCommService.submitTags(
at com.myapppackage.MyApplocation.service.MyAppCommService.onHandleIntent(
at android.os.Handler.dispatchMessage(
at android.os.Looper.loop(

Turns out my context returned null, I fixed it by getting the context in onCreate and calling myContext.startservice.

Answer Source

Fixed it by returning context in the onCreate() and then calling context.startService()

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download