How can I fix this error?
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
ACTIVITY.onNewIntent(Adult1Activity.java:243)
This is the method that includes this error:
private void ExtendedNotification(String time) {
Intent resultIntent = new Intent(this, Adult1Activity.class);
resultIntent.putExtra("A", "restore");
PendingIntent restoreIntent = PendingIntent.getActivity(Adult1Activity.this, 0, resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
resultIntent.putExtra("A", "close");
PendingIntent closeIntent = PendingIntent.getActivity(Adult1Activity.this, 2, resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(Adult1Activity.this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("App Name")
.setContentText(time)
.setAutoCancel(true)
.addAction(new NotificationCompat.Action(R.mipmap.ic_launcher, "Restore", restoreIntent))
.addAction(new NotificationCompat.Action(R.mipmap.ic_launcher, "Close", closeIntent))
.setContentIntent(restoreIntent);
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = notificationBuilder.build();
notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
notificationManager.notify(0, notification);
}
@Override
protected void onNewIntent(Intent intent) {
switch (intent.getStringExtra("A")) {
case "restore":
tv.setText(timeString);
break;
case "close":
countDownTimer.cancel();
isRunning = false;
notificationManager.cancel(0);
CloseApp();
break;
}
I think the problem is not using context in it.
There is a Counter with StopBTN in my app and I create notification with 2 buttons. One of them is RestoreBTN that it shows my ACTIVITY class. Now as I click on StopBTN, this error shows.
EDIT:
There is NullPointer error in handleIntent
method.
private void handleIntent(Intent intent) {
final String a = intent.getStringExtra(EXTRA_NOTE);
if (a != null) {
switch (a) {
case NOTE_RESTORE:
tv.setText(timeString);
notificationManager.cancel(notification_id);
break;
case NOTE_CLOSE:
countDownTimer.cancel();
isRunning = false;
notificationManager.cancel(notification_id);
break;
}
}