java.lang.RuntimeException: Unable to start service com.dexterous.flutterlocalnotifications.ForegroundService@1985771 with Intent { cmp=com.xxx.xxx/com.dexterous.flutterlocalnotifications.ForegroundService (has extras) }: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
E/AndroidRuntime(11842): java.lang.RuntimeException: Unable to start service com.dexterous.flutterlocalnotifications.ForegroundService@1985771 with Intent { cmp=com.zhanghongyang.todo/com.dexterous.flutterlocalnotifications.ForegroundService (has extras) }: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference E/AndroidRuntime(11842): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5408) E/AndroidRuntime(11842): at android.app.ActivityThread.access$3200(ActivityThread.java:283) E/AndroidRuntime(11842): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2584) E/AndroidRuntime(11842): at android.os.Handler.dispatchMessage(Handler.java:109) E/AndroidRuntime(11842): at android.os.Looper.loopOnce(Looper.java:206) E/AndroidRuntime(11842): at android.os.Looper.loop(Looper.java:296) E/AndroidRuntime(11842): at android.app.ActivityThread.main(ActivityThread.java:9047) E/AndroidRuntime(11842): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(11842): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:582) E/AndroidRuntime(11842): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:968) E/AndroidRuntime(11842): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference E/AndroidRuntime(11842): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.setSmallIcon(FlutterLocalNotificationsPlugin.java:463) E/AndroidRuntime(11842): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:364) E/AndroidRuntime(11842): at com.dexterous.flutterlocalnotifications.ForegroundService.onStartCommand(ForegroundService.java:29) E/AndroidRuntime(11842): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5388) E/AndroidRuntime(11842): ... 9 more I/ClientTransactionHandler(11842): send EXECUTE_TRANSACTION I/ClientTransactionHandler(11842): send EXECUTE_TRANSACTION I/Process (11842): Sending signal. PID: 11842 SIG: 9
Same here
Figure it out with AndroidNotificationDetails:
_notificationsPlugin.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()!
..startForegroundService(1, 'Foreground service is running', 'Foreground service',
notificationDetails: AndroidNotificationDetails(
'Foreground service channel',
'Foreground service channel',
channelDescription: 'Foreground service channel description',
importance: Importance.max,
priority: Priority.max,
ongoing: true,
autoCancel: false,
onlyAlertOnce: true,
showWhen: false,
icon: '@drawable/notification_icon',
),
);
It will be good idea to give more clear exception
It's important to provide every argument for the startForegroundService method. Arguments like notificationDetails shouldn't be optional.