Skip to content

Activity.getSharedPreferences(java.lang.String, int)' on a null object reference #129

@chiaberry

Description

@chiaberry

I've encountered some weirdness on Android once my app has been running for a while, I am not sure if theres a bug in my app that is contributing to the error or if the error is what is causing the weirdness.

After my app has been open for a while and I've gone to use other apps, when I come back to my app it is stuck loading. When I close the app and open it again, everything loads fine. (And I am still logged into the package/Spotify.) I finally got some logs and this was near the beginning:

E/AndroidRuntime(30413): java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.SharedPreferences android.app.Activity.getSharedPreferences(java.lang.String, int)' on a null object reference.

and then:

Console 14:56:44 E/AndroidRuntime(30413): at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:106)
Console 14:56:44 E/AndroidRuntime(30413): at com.lufinkey.react.spotify.HTTPRequest.deliverResponse(HTTPRequest.java:39)
Console 14:56:44 E/AndroidRuntime(30413): at com.lufinkey.react.spotify.HTTPRequest.deliverResponse(HTTPRequest.java:88)
Console 14:56:44 E/AndroidRuntime(30413): at com.lufinkey.react.spotify.Utils$1.onResponse(Utils.java:107)
Console 14:56:44 E/AndroidRuntime(30413): at com.lufinkey.react.spotify.Completion.resolve(Completion.java:13)
Console 14:56:44 E/AndroidRuntime(30413): at com.lufinkey.react.spotify.Auth$3.onComplete(Auth.java:313)
Console 14:56:44 E/AndroidRuntime(30413): at com.lufinkey.react.spotify.Auth$3.onComplete(Auth.java:329)
Console 14:56:44 E/AndroidRuntime(30413): at com.lufinkey.react.spotify.Completion.resolve(Completion.java:13)
Console 14:56:44 E/AndroidRuntime(30413): at com.lufinkey.react.spotify.Auth$2.onComplete(Auth.java:222)
Console 14:56:44 E/AndroidRuntime(30413): at com.lufinkey.react.spotify.Auth$2.onComplete(Auth.java:237)
Console 14:56:44 E/AndroidRuntime(30413): at com.lufinkey.react.spotify.Auth.save(Auth.java:70)

So it seems that it only crashes like this when the app is in background and I bring it back up after time has passed. If I put it in background and bring it back up within the next few minutes, its fine. I'll try putting it in background and opening it again after an hour and see if thats when it crashes.

I have the Spotify app on my phone, it's what logs me in to the spotify library.
My phone is a Pixel 3, Android 9. Let me know what other information would be useful.

react-native: 0.59.3
rn-spotify-sdk: 1.2.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions