tyczj
tyczj

Reputation: 73741

NullPointerException in receiver

I have a user getting a NullPointerException in my one BroadcastReceiver the stacktrace is below

java.lang.RuntimeException: Unable to start receiver ecm2.android.NetworkReceiver: java.lang.NullPointerException
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2821)
at android.app.ActivityThread.access$3200(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.content.ComponentName.<init>(ComponentName.java:75)
at android.content.Intent.<init>(Intent.java:2678)
at ecm2.android.NetworkReceiver.onReceive(NetworkReceiver.java:39)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2810)

now obviously something is null but then line that it points to is a pending intent so its hard to tell what is null

here is the code

Context c = MainActivity.getContext();
mAlarmSender2 = PendingIntent.getService(c, 0, new Intent(c, EMGNoteService.class), 0); //line that throws the error

basically I am trying to cancel an AlarmManager that was set so the only thing it could be is the context is null correct?

I am just not sure because the stacktrace is saying something about the ComponentName and Intent so I didnt know if there was something wrong with the intent

Upvotes: 1

Views: 5661

Answers (1)

tyczj
tyczj

Reputation: 73741

the problem was indeed my context so I changed that and it fixed it

Upvotes: 3

Related Questions