此崩溃是无法预测的。我无法复制它。 造成此问题的潜在原因是什么?如何解决?我当时正在考虑尝试捕获,但不确定是否可以解决问题。
发生崩溃的getNotification方法:
Notification getNotification(){
Intent notificationIntent = new Intent(this, PrintQueueActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification notification = new NotificationCompat.Builder(this, GlobalSettings.CHANNEL_PRINT)
.setContentTitle("Print Queue")//this line is 202
.setContentText(getStatus())
.setContentIntent(pendingIntent)
.setSmallIcon(requestError || PrintQueueServiceState.getNumberOfErroredJobs() > 0 ? R.drawable.notify_print_error : R.drawable.notify_print).build();
return notification;
}
仅当从此方法调用getNotification时才发生崩溃。没关系的
private void setErrorState(boolean error){
if(error != requestError){
requestError = error;
startForeground(GlobalSettings.NOTIFICATION_PRINT_QUEUE, getNotification());
if(null != listener){
listener.statusChanged();
}
}
}
这是堆栈跟踪:
Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'java.util.Iterator java.util.List.iterator()' on a null object reference
at android.app.ApplicationPackageManager.getUserIfProfile(ApplicationPackageManager.java:2588)
at android.app.ApplicationPackageManager.getUserBadgeForDensity(ApplicationPackageManager.java:1277)
at android.app.Notification$Builder.getProfileBadgeDrawable(Notification.java:3009)
at android.app.Notification$Builder.hasThreeLines(Notification.java:3234)
at android.app.Notification$Builder.build(Notification.java:3787)
at android.support.v4.app.NotificationCompatBuilder.buildInternal(SourceFile:283)
at android.support.v4.app.NotificationCompatBuilder.build(SourceFile:200)
at android.support.v4.app.NotificationCompat$Builder.build(SourceFile:1505)
at uk.co.app.printing.PrintQueueService.getNotification(SourceFile:202)
at uk.co.app.printing.PrintQueueService.setErrorState(SourceFile:258)
at uk.co.app.printing.PrintQueueService.access$000(SourceFile:49)
at uk.co.app.printing.PrintQueueService$2.onError(SourceFile:221)
at uk.co.app.webservice.WebServiceTask.onPostExecute(SourceFile:197)
at uk.co.app.webservice.WebServiceTask.onPostExecute(SourceFile:42)
at android.os.AsyncTask.finish(AsyncTask.java:632)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6134)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)