Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException for intValue() #672

Closed
felixgabler opened this issue Oct 19, 2022 · 33 comments
Closed

NullPointerException for intValue() #672

felixgabler opened this issue Oct 19, 2022 · 33 comments
Assignees
Labels
bug Something isn't working e2-days Effort: < 5 days flutter Issues related to flutter p2-medium platform-android Android applications specifically

Comments

@felixgabler
Copy link

Plugin Version

2.1.0

Steps to Reproduce

It cannot be reproduced very easily and just occurs for some users of my app. Hoping that the error message itself could lead to a solution. Some implicit cast into int must be incorrect for an argument.

Expected results:
No crashes

Actual results:
The app crashes regularly for many users with

java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
Logs
Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError :  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
	at io.flutter.plugins.googlemobileads.GoogleMobileAdsPlugin.onMethodCall(GoogleMobileAdsPlugin.java:26)
	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:2)
	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:2)
	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0(DartMessenger.java:2)
	at io.flutter.embedding.engine.dart.DartMessenger.a(Unknown Source:0)
	at io.flutter.embedding.engine.dart.a.run(Unknown Source:12)
	at android.os.Handler.handleCallback(Handler.java:938)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:236)
	at android.app.ActivityThread.main(ActivityThread.java:8025)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
). Error thrown null.
[✓] Flutter (Channel stable, 3.3.3, on macOS 12.6 21G115 darwin-arm, locale en-DE)
    • Flutter version 3.3.3 on channel stable at /Users/X/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 18a827f393 (3 weeks ago), 2022-09-28 10:03:14 -0700
    • Engine revision 5c984c26eb
    • Dart version 2.18.2
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/X/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • ANDROID_HOME = /Users/X/Library/Android/sdk
    • Java binary at: /Users/X/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14A400
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Users/X/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] IntelliJ IDEA Ultimate Edition (version 2022.2.3)
    • IntelliJ at /Users/X/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 12.6 21G115 darwin-arm
    • Chrome (web)    • chrome • web-javascript • Google Chrome 106.0.5249.119

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
@huycozy huycozy added the in triage Issue currently being evaluated label Oct 19, 2022
@huycozy
Copy link
Collaborator

huycozy commented Oct 19, 2022

Hi @felixgabler
Do you mean this issue is not reproducible locally? Please try running example code and share the output of flutter run -v.
Also, please provide list of affected device information as well. Thanks!

@huycozy huycozy added the feedback required Further information is requested label Oct 19, 2022
@felixgabler
Copy link
Author

Hi @felixgabler
Do you mean this issue is not reproducible locally? Please try running example code and share the output of flutter run -v.
Also, please provide list of affected device information as well. Thanks!

Yes, it's something I'm getting tons of crashlytics for but it doesn't occur on my phones. So I'm not sure how helpful the output will be. Do you need a list of some of the devices that show up in crashlytics?

@github-actions github-actions bot removed the feedback required Further information is requested label Oct 19, 2022
@huycozy
Copy link
Collaborator

huycozy commented Oct 20, 2022

@felixgabler

Do you need a list of some of the devices that show up in crashlytics?

Yes, we need this info to know which platform is having this issue.

Also, can you try running the app with release mode?

@huycozy huycozy added the feedback required Further information is requested label Oct 20, 2022
@felixgabler
Copy link
Author

Here are the affected devices and platforms:

  • moto e6s, Android 9
  • Nokia G50, Android 12
  • Fairphone 4, Android 11
  • FIG-LX1, Android 9
  • Redmi Note 8, Android 11

For me, everything works even in release mode. Out of thousands of users, it is just these five devices that exhibit the error and I cannot figure out why.

@github-actions github-actions bot removed the feedback required Further information is requested label Oct 20, 2022
@huycozy
Copy link
Collaborator

huycozy commented Oct 20, 2022

@felixgabler All affected devices are Android. Labeling the issue for further insights from the team. Thanks!

@huycozy huycozy added bug Something isn't working p2-medium e2-days Effort: < 5 days platform-android Android applications specifically flutter Issues related to flutter and removed in triage Issue currently being evaluated labels Oct 20, 2022
@PaoloTorregroza
Copy link

Hi! I had the same issue working on my emulator.

I solved it by disposing of the banner when I did not need it anymore.

BannerAd myBanner = BannerAd(.....)

@override
void initState() {
  super.initState()
  myBanner.load()
}

@override
void dispose() {
  super.dispose()
  myBanner.dispose()
}

@hu1won
Copy link

hu1won commented Jan 9, 2023

This error message indicates that you are trying to call the intValue() method on an Integer object which is null. In Java, you cannot call a method on a null object, because a null object does not have any methods to call.

To fix this error, you will need to find the code that is causing the null object to be used, and either provide a non-null object, or check for a null value before calling the method.

Here is an example of how you could modify your code to avoid this error:

Integer myInt = getIntegerValue();
if (myInt != null) {
  int intValue = myInt.intValue();
  // use intValue here
} else {
  // handle the case where myInt is null
}

@hu1won
Copy link

hu1won commented Jan 9, 2023

Alternatively, you could modify the create() method to handle the case where the Integer object is null:

public static void create(@Nullable Integer intValue) {
  if (intValue == null) {
    // handle the case where intValue is null
  } else {
    // use intValue here
  }
}

@CodeWithBishal
Copy link

Hi, I am getting 80 crashes per week.

issue initially created here: flutter/flutter#118082

can I have a update on this?

@huycozy
Copy link
Collaborator

huycozy commented Mar 1, 2023

There are a few recent reports for this as above and the linked duplicate issues.
cc: @jjliu15 for thoughts

@imaNNeo
Copy link

imaNNeo commented Mar 26, 2023

Any update on this issue? I have some similar crash reports

@canewsin
Copy link

Got the exact error trace with thousands of crashes

Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: 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
	at io.flutter.plugins.googlemobileads.h0.onMethodCall(GoogleMobileAdsPlugin.java:26)
	at pa.k$a.a(MethodChannel.java:2)
	at da.c.l(DartMessenger.java:2)
	at da.c.m(DartMessenger.java:3)
	at da.c.i(Unknown Source:0)
	at da.b.run(Unknown Source:12)
	at android.os.Handler.handleCallback(Handler.java:942)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:240)
	at android.os.Looper.loop(Looper.java:351)
	at android.app.ActivityThread.main(ActivityThread.java:8380)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)
)
       at StandardMethodCodec.decodeEnvelope(message_codecs.dart:652)
       at MethodChannel._invokeMethod(platform_channel.dart:310)

@canewsin
Copy link

Got the exact error trace with thousands of crashes...

@huycozy
Screenshot 2023-05-16 001701

@uzumaki258
Copy link

uzumaki258 commented Jun 24, 2023

I have this issue when I go to a screen with native ads for the 2nd time or more in release mode.
The first time was ok. But for 2nd time or more, it always shows this issue. It makes native ads blank.

@mulderpf
Copy link

I am seeing a bunch of these errors in my production environment. I haven't been able to reproduce this locally...yet.

This happened as far back as 2.3.0 and I am currently using 3.0.0 of google_mobile_ads and I am still seeing this issue occur.

From looking through the logs, it never happens upon launch - it is usually after displaying quite a few screens (I mostly only use BannerAds, so it seems to be happening with this). In some of the instances, it seems like the first ad to be loaded after the app was resumed, causes this. (e.g. the last activity happened 9 minutes ago and then the user continues to use the app, the crash happens).

@qiabuqilang
Copy link

Did we get the answer to this issue? I get thousands of crashes about this, every day.......

@mulderpf
Copy link

mulderpf commented Jul 28, 2023

I believe 3.0.1 fixed the issue. I upgraded and didn't see it again. See #853 <-- I was wrong, please ignore this statement.

@felixgabler
Copy link
Author

Has 3.0.1 been released yet? I can only see 3.0.0 in pub.dev

@swenhancer
Copy link

I'm getting the same error on Firebase:

    Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: 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
    	at io.flutter.plugins.googlemobileads.h0.onMethodCall(GoogleMobileAdsPlugin.java:26)
    	at ia.k$a.a(MethodChannel.java:18)
    	at w9.c.l(DartMessenger.java:19)
    	at w9.c.m(DartMessenger.java:41)
    	at w9.c.i(DartMessenger.java:1)
    	at w9.b.run(R8$$SyntheticClass:13)
    	at android.os.Handler.handleCallback(Handler.java:938)
    	at android.os.Handler.dispatchMessage(Handler.java:99)
    	at android.os.Looper.loop(Looper.java:257)
    	at android.app.ActivityThread.main(ActivityThread.java:8220)
    	at java.lang.reflect.Method.invoke(Native Method)
    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:626)
    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1015)

@mulderpf where did you install the v3.0.1 from?

@mulderpf
Copy link

mulderpf commented Aug 16, 2023

I am so sorry, I was clearly very confused when I wrote that I saw it fixed - I muted the issue and just discovered how many people are getting this. I'm still seeing loads and loads of these errors in production.

This is the stacktrace:
Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: 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 at io.flutter.plugins.googlemobileads.GoogleMobileAdsViewFactory.create(Unknown Source:4) at io.flutter.plugin.platform.PlatformViewsController$1.createPlatformView(Unknown Source:51) at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(Unknown Source:34) at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(Unknown Source:263) at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(Unknown Source:175) at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(Unknown Source:17) at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(Unknown Source:18) at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0(Unknown Source:40) at io.flutter.embedding.engine.dart.DartMessenger.a(Unknown Source:0) at io.flutter.embedding.engine.dart.a.run(Unknown Source:12) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8757) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067) ) at StandardMethodCodec.decodeEnvelope(message_codecs.dart:653) at MethodChannel._invokeMethod(platform_channel.dart:315) at SurfaceAndroidViewController._sendCreateMessage(platform_views.dart:1017) at AndroidViewController.create(platform_views.dart:801)

Looking at the Android code of the plugin and the stacktrace above, the issue occurs on line 59 of io.flutter.plugins.googlemobileads.GoogleMobileAdsFactory.java when args is passed with a null value (I don't see any check on the value, so any old junk can make it's way in - which it seems like it is). I am not good with fixing things yet, so won't know where to begin with java code.

@canewsin
Copy link

either google_mobile_ads is not used by many people or people not aware of these issues in their app, 'cause this issues effects 100% of my userbase and still no one from this team taking care of this issue.

@mulderpf
Copy link

It's only affecting a very small number of my users - 24 out of around 8000 a day. I cannot see a pattern really in the devices affected as it is a bit different for me (of course, since the error is happening in the java code, it only affects Android. (I am not seeing anything that's even remotely related in my iOS crash reports).

Device distribution:
Samsung 76%
Huawei 12%
Sony 4%
Oppo 4%
Other 4%

OS distribution:
Android 13 56%
Android 12 16%
Android 9 8%
Android 10 8%
Other 12%

The issue doesn't repeat many times for the same users either - some are using the app for a while and gets it, others don't.

My 90 day stats for this issue: This issue has 1,325 non-fatal events affecting 902 users

This suggests that very few users see this issue happening multiple times - you're likely to only experience it once or twice.

It would be good if this could be triaged further to see if we are potentially losing out on revenue here.

@PatrykIZajac
Copy link

@LTPhantom @imaNNeo Any work in progress on this issue? Error still occurs on Flutter 3.10.6

@huckmin
Copy link

huckmin commented Aug 21, 2023

watching too...

@canewsin
Copy link

what are you guys using alt for this ads package?

@mulderpf
Copy link

Any progress on this? I also noticed this on Interstitial loads. This is revenue impacting so should be investigated asap.

@ManhBanh
Copy link

Any work in progress on this issue?

@tbm98
Copy link

tbm98 commented Sep 24, 2023

I have same issue on production, version 3.0.0

@tbm98
Copy link

tbm98 commented Sep 26, 2023

Alternatively, you could modify the create() method to handle the case where the Integer object is null:

public static void create(@Nullable Integer intValue) {
  if (intValue == null) {
    // handle the case where intValue is null
  } else {
    // use intValue here
  }
}

Hello @hu1won
Where is this snippet in? I want to clone plugin and edit to use locally

@mulderpf
Copy link

How can we fix this? @hu1won where can I find this code that you are referring to?

@BenMiller3
Copy link

Following for updates as looking for any alternatives/solutions to this issue. Thank you!

@hamzaazharr
Copy link

i am also facing crash issue in android 8.0 by calling myBanner.load(); in initState()

@malandr2
Copy link
Collaborator

malandr2 commented Dec 1, 2023

Closing this issue as the fix has been addressed in #967. In the short term you can use

google_mobile_ads:
  git:
    url: https://github.com/googleads/googleads-mobile-flutter
    path: packages/google_mobile_ads

to see the recent changes. This will also be included in the next release (coming this month).

@malandr2 malandr2 closed this as completed Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working e2-days Effort: < 5 days flutter Issues related to flutter p2-medium platform-android Android applications specifically
Projects
None yet
Development

No branches or pull requests