Onesignal-flutter-sdk: [Flutter] - Crash app on Android when get `permissionSubscriptionState` - Failed to handle method call NullPointerException: Attempt to invoke virtual method

Created on 19 Jan 2019  Â·  12Comments  Â·  Source: OneSignal/OneSignal-Flutter-SDK

I got this error, not sure how to fix it:

I/flutter (18349): [PUSH NOTIFICATION] Getting permissionSubscriptionState
E/MethodChannel#OneSignal(18349): Failed to handle method call
E/MethodChannel#OneSignal(18349): java.lang.NullPointerException: Attempt to invoke virtual method 'com.onesignal.OSSubscriptionState com.onesignal.OSPermissionSubscriptionState.getSubscriptionStatus()' on a null object reference
E/MethodChannel#OneSignal(18349):   at com.onesignal.flutter.OneSignalSerializer.convertPermissionSubscriptionStateToMap(OneSignalSerializer.java:47)
E/MethodChannel#OneSignal(18349):   at com.onesignal.flutter.OneSignalPlugin.getPermissionSubscriptionState(OneSignalPlugin.java:167)
E/MethodChannel#OneSignal(18349):   at com.onesignal.flutter.OneSignalPlugin.onMethodCall(OneSignalPlugin.java:76)
E/MethodChannel#OneSignal(18349):   at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:200)
E/MethodChannel#OneSignal(18349):   at io.flutter.view.FlutterNativeView.handlePlatformMessage(FlutterNativeView.java:163)
E/MethodChannel#OneSignal(18349):   at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#OneSignal(18349):   at android.os.MessageQueue.next(MessageQueue.java:325)
E/MethodChannel#OneSignal(18349):   at android.os.Looper.loop(Looper.java:142)
E/MethodChannel#OneSignal(18349):   at android.app.ActivityThread.main(ActivityThread.java:6494)
E/MethodChannel#OneSignal(18349):   at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#OneSignal(18349):   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
E/MethodChannel#OneSignal(18349):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Please check!

Medium Priority

Most helpful comment

@mrgoonie we are still looking into the issue and will fix it in the next release. thanks for bringing it to our attention!

All 12 comments

@mrgoonie Can you please add at least a few more details here? Let me know how you are able to reproduce this problem.

Can you reproduce this issue in our demo app (in the /example folder of this repo)?

The code was copied from your /example:

image

It works just fine on iOS, but when I try it on Android Emulator (Pixel 2), I got that error.

Here is the full log:

E/OneSignal(30626): OneSignal.init has not been called. Could not get OSPermissionSubscriptionState
E/MethodChannel#OneSignal(30626): Failed to handle method call
E/MethodChannel#OneSignal(30626): java.lang.NullPointerException: Attempt to invoke virtual method 'com.onesignal.OSSubscriptionState com.onesignal.OSPermissionSubscriptionState.getSubscriptionStatus()' on a null object reference
E/MethodChannel#OneSignal(30626):   at com.onesignal.flutter.OneSignalSerializer.convertPermissionSubscriptionStateToMap(OneSignalSerializer.java:47)
E/MethodChannel#OneSignal(30626):   at com.onesignal.flutter.OneSignalPlugin.getPermissionSubscriptionState(OneSignalPlugin.java:167)
E/MethodChannel#OneSignal(30626):   at com.onesignal.flutter.OneSignalPlugin.onMethodCall(OneSignalPlugin.java:76)
E/MethodChannel#OneSignal(30626):   at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:200)
E/MethodChannel#OneSignal(30626):   at io.flutter.view.FlutterNativeView.handlePlatformMessage(FlutterNativeView.java:163)
E/MethodChannel#OneSignal(30626):   at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#OneSignal(30626):   at android.os.MessageQueue.next(MessageQueue.java:325)
E/MethodChannel#OneSignal(30626):   at android.os.Looper.loop(Looper.java:142)
E/MethodChannel#OneSignal(30626):   at android.app.ActivityThread.main(ActivityThread.java:6494)
E/MethodChannel#OneSignal(30626):   at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#OneSignal(30626):   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
E/MethodChannel#OneSignal(30626):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
E/flutter (30626): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter (30626): PlatformException(error, Attempt to invoke virtual method 'com.onesignal.OSSubscriptionState com.onesignal.OSPermissionSubscriptionState.getSubscriptionStatus()' on a null object reference, null)
E/flutter (30626): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:551:7)
E/flutter (30626): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:292:18)
E/flutter (30626): <asynchronous suspension>
E/flutter (30626): #2      OneSignal.getPermissionSubscriptionState (package:onesignal/onesignal.dart:209:24)
E/flutter (30626): <asynchronous suspension>
E/flutter (30626): #3      PushNotification.subscribe (package:begreater/config/push_notification.dart:95:22)
E/flutter (30626): <asynchronous suspension>
E/flutter (30626): #4      new Future.delayed.<anonymous closure> (dart:async/future.dart:316:39)
E/flutter (30626): #5      Timer._createTimer.<anonymous closure> (dart:async/runtime/libtimer_patch.dart:21:15)
W/OneSignal(30626):     at android.app.ActivityThread.main(ActivityThread.java:6494)
W/OneSignal(30626):     at java.lang.reflect.Method.invoke(Native Method)
W/OneSignal(30626):     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
W/OneSignal(30626):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
I/flutter (30626): [PUSH NOTIFICATION] Getting permissionSubscriptionState
E/flutter (30626): #6      _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382:19)
E/flutter (30626): #7      _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
E/flutter (30626): #8      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)

Hello,
It looks like the method cannot be called because the OSPermissionSubscriptionState is null. Where are you initializing OneSignal? It would be helpful if you could include your entire dart file.

I would suspect that since this is a Java NPE that the issue would be a bug in our Java wrapper implementation. I will take a deeper look into this shortly. This problem is probably related to GDPR consent being not set while calling getPermissionSubscriptionState

@rgomezp I can't post the dart file because my app structure is complex, but I put the initial code of OneSignal in initState of the first screen. I tried to put it into a button pressed event as well, same issue. Can it be somehow related to Android SDK version? (mine is 27)

@mrgoonie we are still looking into the issue and will fix it in the next release. thanks for bringing it to our attention!

call OneSignal.shared.getPermissionSubscriptionState() after

await OneSignal.shared.init(currentFlavour.oneSignalKey,
iOSSettings: {
OSiOSSettings.autoPrompt: true,
OSiOSSettings.inAppLaunchUrl: true
});

Howdy y'all,
This is quite an old issue so will close. Thanks for your comment @ashkryab

@mrgoonie
I am experiencing the same problem, did you manage to solve it?

➤ Rodrigo Gomez-Palacio commented:

Looks like a potential problem in the bridge @Andres Pelaez ( https://app.asana.com/0/1193998911098051/list )@Jordan Adler ( https://app.asana.com/0/1192863674705800/list )

OneSignal.shared.setRequiresUserPrivacyConsent(false);

this solved the problem for me

Was this page helpful?
0 / 5 - 0 ratings

Related issues

royibernthal picture royibernthal  Â·  8Comments

Allan-Nava picture Allan-Nava  Â·  4Comments

royibernthal picture royibernthal  Â·  3Comments

bhoominn picture bhoominn  Â·  3Comments

sukhcha-in picture sukhcha-in  Â·  11Comments