我想在应用程序上显示通知,但收到通知时出现此错误。
**
D/FLTFireMsgReceiver(14099): broadcast received for message
E/MethodChannel#dexterous.com/flutter/local_notifications(14099): Failed to handle method call
E/MethodChannel#dexterous.com/flutter/local_notifications(14099): 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(14099): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.setSmallIcon(FlutterLocalNotificationsPlugin.java:425)
E/MethodChannel#dexterous.com/flutter/local_notifications(14099): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:326)
E/MethodChannel#dexterous.com/flutter/local_notifications(14099): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java:1146)
E/MethodChannel#dexterous.com/flutter/local_notifications(14099): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.show(FlutterLocalNotificationsPlugin.java:1462)
E/MethodChannel#dexterous.com/flutter/local_notifications(14099): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:1299)
E/MethodChannel#dexterous.com/flutter/local_notifications(14099): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
E/MethodChannel#dexterous.com/flutter/local_notifications(14099): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#dexterous.com/flutter/local_notifications(14099): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/MethodChannel#dexterous.com/flutter/local_notifications(14099): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#dexterous.com/flutter/local_notifications(14099): at android.os.Handler.handleCallback(Handler.java:938)
E/MethodChannel#dexterous.com/flutter/local_notifications(14099): at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#dexterous.com/flutter/local_notifications(14099): at android.os.Looper.loopOnce(Looper.java:233)
E/MethodChannel#dexterous.com/flutter/local_notifications(14099): at android.os.Looper.loop(Looper.java:334)
E/MethodChannel#dexterous.com/flutter/local_notifications(14099): at android.app.ActivityThread.main(ActivityThread.java:8399)
E/MethodChannel#dexterous.com/flutter/local_notifications(14099): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#dexterous.com/flutter/local_notifications(14099): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:582)
E/MethodChannel#dexterous.com/flutter/local_notifications(14099): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068)
E/flutter (14099): [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 (14099): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.setSmallIcon(FlutterLocalNotificationsPlugin.java:425)
E/flutter (14099): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.createNotification(FlutterLocalNotificationsPlugin.java:326)
E/flutter (14099): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.showNotification(FlutterLocalNotificationsPlugin.java:1146)
E/flutter (14099): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.show(FlutterLocalNotificationsPlugin.java:1462)
E/flutter (14099): at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.onMethodCall(FlutterLocalNotificationsPlugin.java:1299)
E/flutter (14099): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
E/flutter (14099): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter (14099): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/flutter (14099): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/flutter (14099): at android.os.Handler.handleCallback(Handler.java:938)
E/flutter (14099): at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter (14099): at android.os.Looper.loopOnce(Looper.java:233)
E/flutter (14099): at android.os.Looper.loop(Looper.java:334)
E/flutter (14099): at android.app.ActivityThread.main(ActivityThread.java:8399)
E/flutter (14099): at java.lang.reflect.Method.invoke(Native Method)
E/flutter (14099): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:582)
E/flutter (14099): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068)
E/flutter (14099): )
E/flutter (14099): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7)
E/flutter (14099): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:315:18)
E/flutter (14099): <asynchronous suspension>
E/flutter (14099): #2 FlutterLocalNotificationsPlugin.show (package:flutter_local_notifications/src/flutter_local_notifications_plugin.dart:239:7)
E/flutter (14099): <asynchronous suspension>
E/flutter (14099):
以下是我的manifest文件:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.aleyia_azadari_schedule"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schemas.android.com/apk/res/android ">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission
android:name="com.google.android.gms.permission.AD_ID"
tools:node="remove" />
<queries>
<intent>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
</intent>
</queries>
<application
android:label="Azadari Schedule"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
android:usesCleartextTraffic="true"
android:showWhenLocked="true"
android:turnScreenOn="true">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<meta-data
android:name="google_analytics_adid_collection_enabled"
android:value="false" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="high_importance_channel" />
</application>
</manifest>
我的图标文件夹的图像
图像以红色显示发射架名称
我被这个问题困住了,解决的办法很好。
下面是我的代码:
//local notification initialization
void initLocalNotifications(BuildContext context, RemoteMessage message) async{
var androidInitializationSettings = AndroidInitializationSettings('@mipmap/ic_launcher');
var initializationSetting = InitializationSettings(
android: androidInitializationSettings
);
await _flutterLocalNotificationsPlugin.initialize(
initializationSetting,
onDidReceiveNotificationResponse: (payload){
}
);
}
flutter_local_notifications:^13.0.0本地通知版本。
1条答案
按热度按时间lyr7nygr1#
根据您提供的信息,您遇到的问题似乎已经在GitHub上得到解决。您可以参考以下链接获取解决方案:https://github.com/MaikuB/flutter_local_notifications/issues/220。希望这将帮助您解决您所面临的问题。