I want to create a notification and I have this bit of code that worked before but now gives me a null pointer at the last line.
Any ideas as to what may cause this?
I know it may be hard with this bit of code that I have provided, I just need a hint as to what could possibly cause this.
private void showNotification() {
CharSequence text = getText(R.string.myString);
Notification notification = new Notification(R.drawable.playbackstart, text,
System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MyActivity.class), 0);
notification.setLatestEventInfo(this, getText(R.string.myString),
text, contentIntent);
mNM.notify(R.string.myString, notification);
}
mNM is null, since R.string.myString must exist otherwise it won’t compile, and notification is used before, therefore cannot be null, otherwise would gotten a NPE earlier. Therefore, check mNM. Or post the entire code where mNM is initialized.