Raf*_*ima 6 service android nullpointerexception foreground-service
我在生产中遇到了 Crashlytics 在少数用户中报告的奇怪异常...我没有太多信息,所以我无法重现它,但我会粘贴 crashlytics 告诉我的所有内容
@SuppressLint("StringFormatMatches")
private void updateForegroundNotification(ServiceStatus status, Object extra) {
Intent notificationIntent = new Intent(this, LoginActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
String text = "sample";
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, Constants.SERVICE_STATUS_NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification_logo)
.setContentTitle(getString(R.string.foregroundNotification))
.setContentText(text)
.setPriority(NotificationCompat.PRIORITY_LOW)
.setContentIntent(pendingIntent);
startForeground(Constants.ID_FOREGROUND_NOTIFICATION, mBuilder.build());//line 656
}
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪
Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'int com.android.server.am.UidRecord.curProcState' on a null object reference
at android.os.Parcel.createException(Parcel.java:1959)
at android.os.Parcel.readException(Parcel.java:1921)
at android.os.Parcel.readException(Parcel.java:1871)
at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:5084)
at android.app.Service.startForeground(Service.java:695)
at com.tomatedigital.giveawaymaster.service.IgiboService.updateForegroundNotification(IgiboService.java:656)
at com.tomatedigital.giveawaymaster.service.IgiboService.login(IgiboService.java:292)
at com.tomatedigital.giveawaymaster.activity.LoginActivity.lambda$doLogin$29(LoginActivity.java:770)
at com.tomatedigital.giveawaymaster.activity.-$$Lambda$LoginActivity$p3_-EGA6SkYcNhRTdeIvZZogf6k.run(-.java:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Run Code Online (Sandbox Code Playgroud)
有谁知道原因以及如何解决?