flutter_local_notifications crashes on Android with Integer.intValue() on a null object reference
Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object referenceShort answer
The crash comes from the small icon. A scheduled notification fired with no icon on the notification, no default icon saved at initialisation and no legacy icon id, so Android got a null number. Upgrade flutter_local_notifications to 23.0.0 or newer, and always give the plugin a default icon that exists as a drawable.
Fix it fast
1Find out which cause you have
Find the plugin version you actually resolved, then read the crash from the device log. If the stack trace goes through setSmallIcon, both causes below apply.
flutter pub deps | grep flutter_local_notifications adb logcat -d | grep -A 12 "intValue()"2Match what you see, then jump to its fix
- 1
The crash happens when a scheduled notification is delivered, often after the app was updated; the plugin version is below 23.0.0An old plugin version crashes when the icon data is missingFix - 2
No icon is set on the notification, and initialize was never given a default icon; the crash shows when a scheduled notification is deliveredThe plugin was never given a small icon that existsFix
- 1
What does the error look like?
Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object referenceNullPointerException in setSmallIcon
Cause 1 of 2
An old plugin version crashes when the icon data is missing
1Check
The plugin's changelog lists a fix in 23.0.0 for exactly this NullPointerException in setSmallIcon, for a scheduled notification delivered with no icon, no persisted default icon and a null legacy icon resource id. The fix falls back to the application's own icon. Compare your resolved version with that.
flutter pub deps | grep flutter_local_notifications
flutter pub outdated2Fix
Upgrade to 23.0.0 or newer. Read the changelog entries between your old version and the new one first, because a newer version can ask for newer Android build settings; the README of the version you move to lists them.
flutter pub upgrade --major-versions flutter_local_notifications3Verify
Schedule a notification a minute ahead, close the app and wait. The notification shows and the log has no new NullPointerException.
adb logcat -d | grep -c "intValue()"Confirmed by raw.githubusercontent.com
Cause 2 of 2
The plugin was never given a small icon that exists
1Check
The plugin takes its default icon from AndroidInitializationSettings, and the README says that icon has to be added as a drawable resource to the Android project. A drawable resource lives under res/drawable. Check that the name you pass has a file there.
grep -rn "AndroidInitializationSettings" lib/
ls android/app/src/main/res/drawable*2Fix
Add a small notification icon as a drawable, pass its name when you initialise the plugin, and optionally name it again on each notification through the icon argument of AndroidNotificationDetails.
// default icon: the file res/drawable/app_icon.png must exist
const AndroidInitializationSettings androidSettings =
AndroidInitializationSettings('app_icon');
// optional, per notification
AndroidNotificationDetails(
channelId,
channelName,
icon: 'app_icon',
)3Verify
Show a notification right away and then a scheduled one. Both appear with your icon.
flutter runConfirmed by pub.dev
How do I stop it coming back?
- Keep flutter_local_notifications current and read its changelog when a major version appears.
- Add the notification icon as a drawable in the first commit that adds notifications, and initialise the plugin with its name.
- Test the scheduled path as well as show(): schedule one a minute ahead and close the app.
- Check release builds too: the plugin's README warns that resources such as notification icons can be removed by R8 unless you keep them.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Mobile apps
Scheduled flutter_local_notifications never appear when the app is closed
zonedSchedule does nothing, with no error shown
Local notifications are scheduled with the system, so they should fire while the app is closed.
5 causes, each with a fixMobile apps
Flutter release build cannot open the keystore: HmacPBESHA256 not available
Algorithm HmacPBESHA256 not available
The keystore is a PKCS12 file protected by a newer algorithm than the Java that is reading it understands.
3 causes, each with a fixMobile apps
Flutter Android build fails: Java is too new for this Gradle version
Unsupported class file major version 61
Gradle only runs on Java versions it knows.
3 causes, each with a fixMobile apps
Flutter Android: Failed to load FirebaseOptions from resource
Failed to load FirebaseOptions from resource. Check that you have defined values.xml correctly.
On Android, Firebase reads its settings from a values.xml file that the Google services Gradle plugin builds from google-services.json.
4 causes, each with a fixMobile apps
Flutter Android build stops with Execution failed for task ':app:…'
Execution failed for task ':app:compileFlutterBuildRelease'.
The line only tells you which Gradle step broke; the task name in the quotes tells you why.
5 causes, each with a fixMobile apps
Flutter's Android build stops: JAVA_HOME is not set
ERROR: JAVA_HOME is set to an invalid directory
The Gradle wrapper script needs a Java runtime and looks in two places: the JAVA_HOME variable, then a java command on PATH.
3 causes, each with a fix