23

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

Jaymin
  • 2,879
  • 3
  • 19
  • 35
user3162215
  • 357
  • 1
  • 9

1 Answers1

-4

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.

Piotr Wittchen
  • 3,853
  • 4
  • 26
  • 39
  • 1
    Nope, mNotification is not null when buildNotification(); is called – user3162215 Jun 12 '19 at 02:06
  • So if `NOTIFICATION_ID_TOOLBAR` is not `null` too, then there will be `null` somewhere inside `startForeground(...)` method, but I have no idea where. It needs to be debugged. – Piotr Wittchen Jun 12 '19 at 08:24