guys. How are you all doing? Good I hope.
I have a question regarding crash reports from my app, more specifically when receiving a notification. As far as I was able to test the application, it had no issues with showing it's notifications, but in Google Play Console, I have multiple crash reports, telling me that there has been a Null Pointer Exception
This is my crash report right here:
java.lang.RuntimeException: at android.app.ActivityThread.handleReceiver (ActivityThread.java:3098)
at android.app.ActivityThread.-wrap18 (ActivityThread.java) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1588) at android.os.Handler.dispatchMessage (Handler.java:102) at android.os.Looper.loop (Looper.java:154) at android.app.ActivityThread.main (ActivityThread.java:6247) at java.lang.reflect.Method.invoke (Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:872) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762) Caused by: java.lang.NullPointerException: at com.tedosoft.carmaintenance.AlertReceiver.onReceive (AlertReceiver.java:24) at android.app.ActivityThread.handleReceiver (ActivityThread.java:3091)
And this is the specific line (AlertReceiver.java:24)
in my code:
if (intent.getStringExtra("id").equals("autoUpdate"))
And the full code to that line:
Bundle extras = intent.getExtras();
if (extras != null){
if (intent.getStringExtra("id").equals("autoUpdate")) {
doAutoUpdate(context, context.getString(R.string.notification_auto_add_title),
context.getString(R.string.notification_auto_add_text),
context.getString(R.string.notification_auto_add_title));
}
The entire code for onReceive
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null){
if (intent.getStringExtra("id").equals("autoUpdate")) {
doAutoUpdate(context, context.getString(R.string.notification_auto_add_title),
context.getString(R.string.notification_auto_add_text),
context.getString(R.string.notification_auto_add_title));
}
if (intent.getStringExtra("id").equals("updateReminder")) {
createNotification(context, context.getString(R.string.notification_title),
context.getString(R.string.notification_text),
context.getString(R.string.notification_title));
}
if (intent.getStringExtra("id").equals("reminder")) {
List<Integer> activeRemindersRowIds = getActiveRemindersCarRowIds(context);
for (int j = 0; j < activeRemindersRowIds.size(); j++) {
createNotificationReminder(context, activeRemindersRowIds.get(j),
context.getString(R.string.notification_reminder_text),
context.getString(R.string.notification_reminder_ticker));
}
}
}
}
What I suspect I am doing wrong here, is that most probably I should be typing in if(extras.getString("id).equals("autoUpdate"))
instead of what it is at the moment, but I would like you to confirm that for me, before jumping to any conclusions.
So what I am asking here is - Why is my application crashing on that line of code and how can I fix this?
The crash report is only for that line and the other if statements
do not cause crashes.