flutter_local_notifications
flutter_local_notifications copied to clipboard
NullPointerException Attempt to invoke virtual method 'int java.lang.Integer.intValue()
We see this crash happens to our Android users. All the crashes happen when the app is in the background. Plugin version 6.0.0. Android versions 9-11.
Crash log:
Fatal Exception: java.lang.RuntimeException: Unable to start receiver com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4035)
at android.app.ActivityThread.access$1400(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1924)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7664)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.scheduleNotification(FlutterLocalNotificationsPlugin.java:329)
at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.rescheduleNotifications(FlutterLocalNotificationsPlugin.java:147)
at com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver.onReceive(ScheduledNotificationBootReceiver.java:21)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4026)
at android.app.ActivityThread.access$1400(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1924)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7664)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Same Issue :(
[Solved]- Duplicate https://github.com/MaikuB/flutter_local_notifications/issues/220
please pin it.
@rtokun has the release build configuration with Proguard rules etc been done properly?
@vimalmistry that issue you're referring is to do with not having setup the icon properly. There are links in the readme on understanding the Android resource system, statements to say the icon should be a drawable resource and a link to a complete example app to demonstrate
Same issue here: But just for a few users
Fatal Exception: java.lang.RuntimeException: Unable to start receiver com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3808)
at android.app.ActivityThread.-wrap18(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2082)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7523)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.setupNotificationChannel(FlutterLocalNotificationsPlugin.java:22)
at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:14)
at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java)
at com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver.onReceive(ScheduledNotificationReceiver.java:76)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3798)
at android.app.ActivityThread.-wrap18(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2082)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7523)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
make sure you define the notification icon name while showing the notification, inside notification details. I had faced the same and was stuck for hours.
notificationsPlugin.show(
DateTime.now().millisecond,
message.notification?.title,
message.notification?.body,
NotificationDetails(
android: AndroidNotificationDetails(
channelId,
channelName,
icon: "ic_notification",
priority: Priority.max,
importance: Importance.max,
enableVibration: true,
),
),
payload: json.encode(message.data),
);
I am getting the same error, but just for like 2 or 3 users
make sure you define the notification icon name while showing the notification, inside notification details. I had faced the same and was stuck for hours.
notificationsPlugin.show( DateTime.now().millisecond, message.notification?.title, message.notification?.body, NotificationDetails( android: AndroidNotificationDetails( channelId, channelName, icon: "ic_notification", priority: Priority.max, importance: Importance.max, enableVibration: true, ), ), payload: json.encode(message.data), );
Still seeing the same error even with icon param filled.
make sure you define the notification icon name while showing the notification, inside notification details. I had faced the same and was stuck for hours.
notificationsPlugin.show( DateTime.now().millisecond, message.notification?.title, message.notification?.body, NotificationDetails( android: AndroidNotificationDetails( channelId, channelName, icon: "ic_notification", priority: Priority.max, importance: Importance.max, enableVibration: true, ), ), payload: json.encode(message.data), );
This solved it for me. Why isn't android.smallIcon
returning the string for us? Also this should be in the docs or something. Thanks for helping us!
make sure you define the notification icon name while showing the notification, inside notification details. I had faced the same and was stuck for hours.
notificationsPlugin.show( DateTime.now().millisecond, message.notification?.title, message.notification?.body, NotificationDetails( android: AndroidNotificationDetails( channelId, channelName, icon: "ic_notification", priority: Priority.max, importance: Importance.max, enableVibration: true, ), ), payload: json.encode(message.data), );
Thank your help. It work for me. For anyone don't know, you just add your icon on drawable from android/app/src/main/res/drawable/app_icon.png. The "app_icon" name you must put on "icon" params of AndroidNotificationDetails class. Like this AndroidNotificationDetails(icon: 'app_icon')
Thank you so much! This saved me after being blocked for days.
Closing this as OP hasn't provided further information and the rest of the messages in this thread here point to not looking into the docs linked in the readme to understand how resources work in Android
MaikuB blaming the people who have read the docs instead of just quietly closing the issue and maybe adding better error checkin in their API.
If anyone still facing the bug, all you have to do it is to define AndroidNotificationDetails