NPE when startForeground

Viewed 1056

NPE reported in crashlytics only for Android O and above. I just startForegroundService and the service startForground in onCreate method and the NPE happened.

In crashlytics it happened when startForeground(NOTIFICATION_ID_TOOLBAR, mNotification);

@Override
public void onCreate() {
    super.onCreate();
    buildNotification();
    startForeground(NOTIFICATION_ID_TOOLBAR, mNotification);
}

Unable to create service ToolbarService: java.lang.NullPointerException: Attempt to read from field 'int com.android.server.am.UidRecord.curProcState' on a null object reference

1 Answers

Probably mNotification value is null. You need to analyze your code to figure out why and when. This code snippet is to short to perform any analysis.

Related