flutter_local_notifications icon indicating copy to clipboard operation
flutter_local_notifications copied to clipboard

NullPointerException Attempt to invoke virtual method 'int java.lang.Integer.intValue()

Open rtokun opened this issue 3 years ago • 7 comments

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)

rtokun avatar Jul 22 '21 07:07 rtokun

Same Issue :(

vimalmistry avatar Jul 25 '21 14:07 vimalmistry

[Solved]- Duplicate https://github.com/MaikuB/flutter_local_notifications/issues/220

please pin it.

vimalmistry avatar Jul 25 '21 16:07 vimalmistry

@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

MaikuB avatar Jul 29 '21 07:07 MaikuB

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)

uzumaki258 avatar Oct 17 '21 08:10 uzumaki258

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),
    );

omar-khaium avatar Nov 09 '21 05:11 omar-khaium

I am getting the same error, but just for like 2 or 3 users

armandojimenez avatar Dec 11 '21 01:12 armandojimenez

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.

armandojimenez avatar Mar 15 '22 21:03 armandojimenez

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!

TheMaverickProgrammer avatar Sep 19 '22 00:09 TheMaverickProgrammer

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')

dungnguyentri3110 avatar Jan 04 '23 03:01 dungnguyentri3110

Thank you so much! This saved me after being blocked for days.

codemicah avatar Feb 24 '23 17:02 codemicah

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 avatar Feb 25 '23 02:02 MaikuB

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.

TheMaverickProgrammer avatar Feb 25 '23 03:02 TheMaverickProgrammer

If anyone still facing the bug, all you have to do it is to define AndroidNotificationDetails

EchoEllet avatar Dec 25 '23 10:12 EchoEllet