Describe the bug
E/MethodChannel#dexterous.com/flutter/local_notifications(16232): Failed to handle method call
E/MethodChannel#dexterous.com/flutter/local_notifications(16232): java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.setSmallIcon(FlutterLocalNotificationsPlugin.java:463)
E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:364)
E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java:1248)
E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.show(FlutterLocalNotificationsPlugin.java:1588)
E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:1413)
E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at android.os.Handler.handleCallback(Handler.java:958)
E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at android.os.Looper.loopOnce(Looper.java:205)
E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at android.os.Looper.loop(Looper.java:294)
E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at android.app.ActivityThread.main(ActivityThread.java:8177)
E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
E/flutter (16232): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
E/flutter (16232): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.setSmallIcon(FlutterLocalNotificationsPlugin.java:463)
E/flutter (16232): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:364)
E/flutter (16232): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java:1248)
E/flutter (16232): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.show(FlutterLocalNotificationsPlugin.java:1588)
E/flutter (16232): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:1413)
E/flutter (16232): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
E/flutter (16232): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)
E/flutter (16232): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
E/flutter (16232): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/flutter (16232): at android.os.Handler.handleCallback(Handler.java:958)
E/flutter (16232): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter (16232): at android.os.Looper.loopOnce(Looper.java:205)
E/flutter (16232): at android.os.Looper.loop(Looper.java:294)
E/flutter (16232): at android.app.ActivityThread.main(ActivityThread.java:8177)
E/flutter (16232): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (16232): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
E/flutter (16232): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
E/flutter (16232): )
E/flutter (16232): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:651:7)
E/flutter (16232): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)
E/flutter (16232):
E/flutter (16232): #2 FlutterLocalNotificationsPlugin.show (package:flutter_local_notifications/src/flutter_local_notifications_plugin.dart:240:7)
E/flutter (16232):
To Reproduce
Go to firebase cloud messaging
Click on send test message
Sample code to reproduce the problem
import 'dart:math';
Describe the bug E/MethodChannel#dexterous.com/flutter/local_notifications(16232): Failed to handle method call E/MethodChannel#dexterous.com/flutter/local_notifications(16232): java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.setSmallIcon(FlutterLocalNotificationsPlugin.java:463) E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:364) E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java:1248) E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.show(FlutterLocalNotificationsPlugin.java:1588) E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:1413) E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267) E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292) E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319) E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at android.os.Handler.handleCallback(Handler.java:958) E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at android.os.Handler.dispatchMessage(Handler.java:99) E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at android.os.Looper.loopOnce(Looper.java:205) E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at android.os.Looper.loop(Looper.java:294) E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at android.app.ActivityThread.main(ActivityThread.java:8177) E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) E/MethodChannel#dexterous.com/flutter/local_notifications(16232): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971) E/flutter (16232): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference E/flutter (16232): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.setSmallIcon(FlutterLocalNotificationsPlugin.java:463) E/flutter (16232): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:364) E/flutter (16232): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java:1248) E/flutter (16232): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.show(FlutterLocalNotificationsPlugin.java:1588) E/flutter (16232): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:1413) E/flutter (16232): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267) E/flutter (16232): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292) E/flutter (16232): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319) E/flutter (16232): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) E/flutter (16232): at android.os.Handler.handleCallback(Handler.java:958) E/flutter (16232): at android.os.Handler.dispatchMessage(Handler.java:99) E/flutter (16232): at android.os.Looper.loopOnce(Looper.java:205) E/flutter (16232): at android.os.Looper.loop(Looper.java:294) E/flutter (16232): at android.app.ActivityThread.main(ActivityThread.java:8177) E/flutter (16232): at java.lang.reflect.Method.invoke(Native Method) E/flutter (16232): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) E/flutter (16232): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971) E/flutter (16232): ) E/flutter (16232): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:651:7) E/flutter (16232): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18) E/flutter (16232):
E/flutter (16232): #2 FlutterLocalNotificationsPlugin.show (package:flutter_local_notifications/src/flutter_local_notifications_plugin.dart:240:7)
E/flutter (16232):
To Reproduce
Sample code to reproduce the problem import 'dart:math';
import 'package:app_settings/app_settings.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart';
class NotificationServices { FirebaseMessaging messaging = FirebaseMessaging.instance; final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
void requestNotificationPermission() async { NotificationSettings settings = await messaging.requestPermission( alert: true, announcement: false, badge: true, carPlay: false, criticalAlert: false, provisional: false, sound: true, ); if (settings.authorizationStatus == AuthorizationStatus.authorized) { print('User granted permission'); } else if (settings.authorizationStatus == AuthorizationStatus.provisional) { print('User granted provisional permission'); } else { AppSettings.openAppSettings( type: AppSettingsType.notification, ); } }
void initLocalNotifications( BuildContext context, RemoteMessage message) async { var androidInit = AndroidInitializationSettings('@drawable/ic_launcher'); var iosInit = DarwinInitializationSettings();
}
void firebaseInit() { FirebaseMessaging.onMessage.listen((message) { showNotification(message); }); }
Future showNotification(RemoteMessage message) async {
AndroidNotificationChannel channel = AndroidNotificationChannel(
Random.secure().nextInt(1000).toString(),
'High Importance Notifications',
description: 'This channel is used for important notifications',
importance: Importance.max,
playSound: true,
enableVibration: true,
);
var androidDetails = AndroidNotificationDetails(
channel.id,
channel.name,
channelDescription: channel.description,
importance: Importance.max,
playSound: true,
enableVibration: true,
ticker: 'ticker',
);
}
Future<String?> getDeviceToken() async { return await messaging.getToken(); }
//if token refresh void onTokenRefresh() async { messaging.onTokenRefresh.listen((event) { event.toString(); }); } }