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 boolean com.onesignal.OneSignal$Builder.mPromptLocation #811

Closed
KonstantinosReppas opened this issue Jul 22, 2019 · 35 comments · Fixed by #825
Closed
Labels
Possible Bug Maintainers need to confirm or reproduce

Comments

@KonstantinosReppas
Copy link

KonstantinosReppas commented Jul 22, 2019

Hello, I am getting this error:

java.lang.NullPointerException: Attempt to read from field 'boolean com.onesignal.OneSignal$Builder.mPromptLocation' on a null object reference

Caused by: java.lang.NullPointerException: Attempt to read from field 'boolean com.onesignal.OneSignal$Builder.mPromptLocation' on a null object reference
        at com.onesignal.OneSignal.startLocationUpdate(OneSignal.java:866)
        at com.onesignal.OneSignal.startRegistrationOrOnSession(OneSignal.java:847)
        at com.onesignal.OneSignal.doSessionInit(OneSignal.java:762)
        at com.onesignal.OneSignal.onAppFocus(OneSignal.java:1214)
        at com.onesignal.ActivityLifecycleHandler.handleFocus(ActivityLifecycleHandler.java:207)
        at com.onesignal.ActivityLifecycleHandler.onActivityResumed(ActivityLifecycleHandler.java:121)
        at com.onesignal.ActivityLifecycleListener.onActivityResumed(ActivityLifecycleListener.java:78)
        at android.app.Application.dispatchActivityResumed(Application.java:216)
        at android.app.Activity.onResume(Activity.java:1306)

gradle :

api 'com.onesignal:OneSignal:[3.10.2, 3.99.99]'      (3.11.1)

reproduction:
Exception sometimes occurs when clicking on a notification and user is logged out.

@rgomezp rgomezp added the Possible Bug Maintainers need to confirm or reproduce label Jul 22, 2019
@KonstantinosReppas
Copy link
Author

Small update: Crash occurs also when app is in background randomly.

@rgomezp
Copy link
Contributor

rgomezp commented Jul 24, 2019

Howdy,
Can you make sure to initialize OneSignal in the application file instead of the main activity?

@KonstantinosReppas
Copy link
Author

As we need to have a dynamic key for initialization, do we need to init it during the onCreate() of Application class, or it can be initialized anytime as long as the initialization occurs in Application class?
Thank you

@alvin986
Copy link

We're having the same issue. Happens when resuming to application after longer time being in background.

java.lang.NullPointerException: Attempt to read from field 'boolean com.onesignal.OneSignal$Builder.mPromptLocation' on a null object reference at com.onesignal.OneSignal.startLocationUpdate(OneSignal.java:866) at com.onesignal.OneSignal.startRegistrationOrOnSession(OneSignal.java:847) at com.onesignal.OneSignal.doSessionInit(OneSignal.java:762) at com.onesignal.OneSignal.onAppFocus(OneSignal.java:1214) at com.onesignal.ActivityLifecycleHandler.handleFocus(ActivityLifecycleHandler.java:207) at com.onesignal.ActivityLifecycleHandler.onActivityResumed(ActivityLifecycleHandler.java:121) at com.onesignal.ActivityLifecycleListener.onActivityResumed(ActivityLifecycleListener.java:78) at android.app.Application.dispatchActivityResumed(Application.java:239) at android.app.Activity.onResume(Activity.java:1343) at android.support.v4.app.FragmentActivity.onResume(FragmentActivity.java:514) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1412) at android.app.Activity.performResume(Activity.java:7292) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3807) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3847) at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1836) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6702) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)

Android 8
Android 8.1
Android 9

@alvin986
Copy link

alvin986 commented Jul 28, 2019

To reproduce on Android 8 :
Open your application, go to Android settings, Applications, disable location permission.
Everything works.
Open your application, go o Android settings, disable Location within the Android settings,
press back to go back to your application and you get the above error.

EDIT : I also noticed that when you set autoPromptLocation property to true or false problem goes away.

EDIT2 : Problem still persists in production after setting autoPromptLocation property.

@smartties
Copy link

Same issue with 3.11.1, i have too many crash (1% of user bases)
i'm rolling back to 3.10.6 which was more stable for me.

@alvin986
Copy link

Same issue with 3.11.1, i have too many crash (1% of user bases)
i'm rolling back to 3.10.6 which was more stable for me.

3.10.6 is stable ?

@smartties
Copy link

Well it crash less than 3.11.1

@mikechoch
Copy link
Contributor

mikechoch commented Jul 30, 2019

When you initialize the OneSignal SDK it should be done within an extended Application onCreate method.

For Example:

public class YourAppClass extends Application {
   @Override
   public void onCreate() {
      super.onCreate();
     
      // OneSignal Initialization
      OneSignal.startInit(this)
        .inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
        .unsubscribeWhenNotificationsAreDisabled(true)
        .init();
   }
}

This gives our SDK the application context, instead of activity context, which is suspected to be causing these issues. Please confirm that this is similar to how you are initializing the OneSignal SDK in your app.

A link to this setup is shown below, but it is easy to mistake calling init() within an extended Activity instead of the Application onCreate(). In the mean time, we will add logging for future users so this issue does not occur and also so that no crash occurs within any apps using our SDK.

Another case I can think of is that you're using the Privacy Consent for our SDK and the builder is not being setup for some reason. Are you using our Privacy Consent methods?

@alvin986
Copy link

Hi,

SDK is initialised within onCreate().

We rolled back to 3.10.6 and crashing is gone.

We are using Privacy Consent methods.

@KonstantinosReppas
Copy link
Author

We are rolling back for now because we cannot init during onCreate, as we first need to request the key from our server (it is dynamic depending on the region).
We will eagerly keep an eye for a fix to allow us to get back to the newest version, but as of now, rolling back is the safest option.

@heykooldude
Copy link

heykooldude commented Jul 31, 2019

We are facing this same issue running 3.10.9

java.lang.RuntimeException:
 
  at android.app.ActivityThread.performResumeActivity (ActivityThread.java:3121)
 
  at android.app.ActivityThread.handleResumeActivity (ActivityThread.java:3152)
 
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1398)
 
  at android.os.Handler.dispatchMessage (Handler.java:102)
 
  at android.os.Looper.loop (Looper.java:148)
 
  at android.app.ActivityThread.main (ActivityThread.java:5443)
 
  at java.lang.reflect.Method.invoke (Native Method)
 
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:728)
 
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:618)


Caused by: java.lang.NullPointerException: 
 
  at com.onesignal.OneSignal.startLocationUpdate (OneSignal.java:866)
 
  at com.onesignal.OneSignal.startRegistrationOrOnSession (OneSignal.java:847)
 
  at com.onesignal.OneSignal.doSessionInit (OneSignal.java:762)
 
  at com.onesignal.OneSignal.onAppFocus (OneSignal.java:1214)
 
  at com.onesignal.ActivityLifecycleHandler.handleFocus (ActivityLifecycleHandler.java:207)
 
  at com.onesignal.ActivityLifecycleHandler.onActivityResumed (ActivityLifecycleHandler.java:121)
 
  at com.onesignal.ActivityLifecycleListener.onActivityResumed (ActivityLifecycleListener.java:78)
 
  at android.app.Application.dispatchActivityResumed (Application.java:214)
 
  at android.app.Activity.onResume (Activity.java:1211)
 
  at androidx.fragment.app.FragmentActivity.onResume (FragmentActivity.java:514)
 
  at android.app.Instrumentation.callActivityOnResume (Instrumentation.java:1281)
 
  at android.app.Activity.performResume (Activity.java:6320)
 
  at android.app.ActivityThread.performResumeActivity `(ActivityThread.java:3110)

@mikechoch
Copy link
Contributor

Further investigation led to finding the root cause, this should be fixed in the next release.

@smartties
Copy link

smartties commented Aug 4, 2019

@mikechoch Will we be able to keep the init of the OneSignal SDK inside the onCreate of Activity (or is it mandatory to do it inside the Application class) in the next release ?

@jkasten2
Copy link
Member

jkasten2 commented Aug 4, 2019

@smartties It is highly recommend to init the OneSignal SDK from the onCreate of your Application class. This is recommended since it can always grab an Activity Context as soon as it is available, without needing to init the OneSignal SDK from every Activity onCreate.

If for some reason you can't init from the onCreate of your Application class then ensure you are giving OneSignal an Activity instance if an Activity is in focus as some features of OneSignal require an Activity Context.

@nhnpro
Copy link

nhnpro commented Aug 8, 2019

@mikechoch any plan to fix this bug for Unity SDK ? Cause as I seen UnitySDK still use an old version, and my game currently have many crashes from this exception.

@rgomezp
Copy link
Contributor

rgomezp commented Aug 8, 2019

We will release a new Unity SDK version very soon! Thanks for your patience

@jkasten2
Copy link
Member

jkasten2 commented Aug 9, 2019

Just following up to note that this issue was fixed in version 3.11.2
https://github.com/OneSignal/OneSignal-Android-SDK/releases/tag/3.11.2

@KristapsKrumins
Copy link

KristapsKrumins commented Aug 14, 2019

Gradle:

api "com.google.android.gms:play-services-base:17.0.0"   
api "com.google.android.gms:play-services-analytics:17.0.0"   
api ('com.onesignal:OneSignal:3.11.2') {
        exclude group:'com.google.android.gms'
        exclude group:'com.google.firebase'
}

Getting the same error even though I am not using OneSignal. That is I have not called OneSignal.startInit() or used any OneSignal class. Do I need to call OneSignal.startInit() even though I am not using it?

@jkasten2
Copy link
Member

@KristapsKrumins Can you share your full stacktrace and steps to reproduce the crash?

@jkasten2 jkasten2 reopened this Aug 14, 2019
@tecpg
Copy link

tecpg commented Aug 14, 2019

Hello guys, a friend introduced me to Onesignal as a better platform for push messaging, i have been using it for a month now but this crash error keeps popping up :

Caused by: java.lang.NullPointerException:
at com.onesignal.OneSignal.startLocationUpdate (OneSignal.java:865)
at com.onesignal.OneSignal.startRegistrationOrOnSession (OneSignal.java:846)

Please any solution yet???

@KristapsKrumins
Copy link

KristapsKrumins commented Aug 14, 2019

@jkasten2
Stacktrace:

Fatal Exception: java.lang.RuntimeException: Unable to resume activity {packagename/packagename.XActivity}: java.lang.NullPointerException: Attempt to read from field 'boolean com.onesignal.OneSignal$Builder.mPromptLocation' on a null object reference
       at android.app.ActivityThread.performResumeActivity + 2990(ActivityThread.java:2990)
       at android.app.ActivityThread.handleResumeActivity + 3021(ActivityThread.java:3021)
       at android.app.ActivityThread.handleLaunchActivity + 2396(ActivityThread.java:2396)
       at android.app.ActivityThread.access$800 + 151(ActivityThread.java:151)
       at android.app.ActivityThread$H.handleMessage + 1307(ActivityThread.java:1307)
       at android.os.Handler.dispatchMessage + 102(Handler.java:102)
       at android.os.Looper.loop + 135(Looper.java:135)
       at android.app.ActivityThread.main + 5258(ActivityThread.java:5258)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke + 372(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run + 903(ZygoteInit.java:903)
       at com.android.internal.os.ZygoteInit.main + 698(ZygoteInit.java:698)
Caused by java.lang.NullPointerException: Attempt to read from field 'boolean com.onesignal.OneSignal$Builder.mPromptLocation' on a null object reference
       at com.onesignal.OneSignal.startLocationUpdate + 865(OneSignal.java:865)
       at com.onesignal.OneSignal.startRegistrationOrOnSession + 846(OneSignal.java:846)
       at com.onesignal.OneSignal.doSessionInit + 761(OneSignal.java:761)
       at com.onesignal.OneSignal.onAppFocus + 1222(OneSignal.java:1222)
       at com.onesignal.ActivityLifecycleHandler.handleFocus + 207(ActivityLifecycleHandler.java:207)
       at com.onesignal.ActivityLifecycleHandler.onActivityResumed + 121(ActivityLifecycleHandler.java:121)
       at com.onesignal.ActivityLifecycleListener.onActivityResumed + 78(ActivityLifecycleListener.java:78)
       at android.app.Application.dispatchActivityResumed + 208(Application.java:208)
       at android.app.Activity.onResume + 1220(Activity.java:1220)
       at androidx.fragment.app.FragmentActivity.onResume + 514(FragmentActivity.java:514)
       at X.BaseActivity.onResume + 31(BaseActivity.kt:31)
       at X.XBaseActivity.onResume + 99(XBaseActivity.kt:99)
       at android.app.Instrumentation.callActivityOnResume + 1257(Instrumentation.java:1257)
       at android.app.Activity.performResume + 6076(Activity.java:6076)
       at android.app.ActivityThread.performResumeActivity + 2979(ActivityThread.java:2979)
       at android.app.ActivityThread.handleResumeActivity + 3021(ActivityThread.java:3021)
       at android.app.ActivityThread.handleLaunchActivity + 2396(ActivityThread.java:2396)
       at android.app.ActivityThread.access$800 + 151(ActivityThread.java:151)
       at android.app.ActivityThread$H.handleMessage + 1307(ActivityThread.java:1307)
       at android.os.Handler.dispatchMessage + 102(Handler.java:102)
       at android.os.Looper.loop + 135(Looper.java:135)
       at android.app.ActivityThread.main + 5258(ActivityThread.java:5258)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke + 372(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run + 903(ZygoteInit.java:903)
       at com.android.internal.os.ZygoteInit.main + 698(ZygoteInit.java:698)

I have not been able to reproduce the crash, but it is the most common crash in Crashlytics after we updated from 3.6.5 to 3.11.2. OneSignal is included in core module.

@NeoTT
Copy link

NeoTT commented Aug 16, 2019

Has this issue been resolved in 3.11.2 ? We are also getting lot of these issues.

@ikitae
Copy link

ikitae commented Aug 16, 2019

3.11.2 still crash

@orhnzsy
Copy link

orhnzsy commented Aug 20, 2019

We are facing same issue on unity sdk 2.8.2 version. We are not using Privacy consent methods and can't reproduce it. It is only shows on analytics. I don't think it is related to privacy consent.

@NeoTT
Copy link

NeoTT commented Aug 22, 2019

When can we expect a new sdk for unity with this bug fix?

@iballan
Copy link

iballan commented Aug 25, 2019

Onesignal has become the hero of my ANRs & crashes reports on Play Store with this issue

Caused by: java.lang.NullPointerException: 
at com.onesignal.OneSignal.startLocationUpdate (OneSignal.java:865)
  at com.onesignal.OneSignal.startRegistrationOrOnSession (OneSignal.java:846)
  at com.onesignal.OneSignal.doSessionInit (OneSignal.java:761)
  at com.onesignal.OneSignal.onAppFocus (OneSignal.java:1222)
  at com.onesignal.ActivityLifecycleHandler.handleFocus (ActivityLifecycleHandler.java:207)
  at com.onesignal.ActivityLifecycleHandler.onActivityResumed (ActivityLifecycleHandler.java:121)
  at com.onesignal.ActivityLifecycleListener.onActivityResumed (ActivityLifecycleListener.java:78)

Getting the crash on:
Android 9.0
Android 8.1
Android 8.0
Android 7.0
Android 6.0
Android 7.1
Android 4.4
Android 5.1
Android 5.0

Screen Shot 2019-08-25 at 4 36 36 PM

I hope there will be a quick update for this issue!

@tecpg
Copy link

tecpg commented Aug 25, 2019 via email

@tecpg
Copy link

tecpg commented Aug 25, 2019

Same here, i have been waiting for a fix now over a month, very scary...

@EmilAlipiev
Copy link

EmilAlipiev commented Sep 8, 2019

Xamarin.android has the same problem. Why is that even close without a proper fix? Can you please advise?

@HBiSoft
Copy link

HBiSoft commented Sep 10, 2019

@iballan Can you please confirm if the new release fixed this issue?

@rgomezp
Copy link
Contributor

rgomezp commented Sep 11, 2019

Howdy @EmilAlipiev ,
This was closed because it has been fixed in this repository

@JPerryOddGames
Copy link

@nhnpro @orhnzsy @NeoTT OneSignal Unity SDK 2.9.0 has now been released with this fix included

@iamatulkumar
Copy link

Facing same issue in One signal flutter SDK

@vlimag
Copy link

vlimag commented Aug 4, 2023

Any updates on this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Possible Bug Maintainers need to confirm or reproduce
Projects
None yet
Development

Successfully merging a pull request may close this issue.