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

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.json.JSONObject.optString(java.lang.String)' on a null object reference #5

Closed
krottv opened this issue Feb 11, 2021 · 10 comments

Comments

@krottv
Copy link

krottv commented Feb 11, 2021

When calling Adapty.restorePurchases. I use the last version of adapty lib.

 java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.json.JSONObject.optString(java.lang.String)' on a null object reference
        at com.android.billingclient.api.SkuDetails.getDescription(com.android.billingclient:billing@@3.0.2:1)
        at com.adapty.api.entity.restore.RestoreItem.setDetails(RestoreItem.kt:42)
        at com.adapty.purchase.InAppPurchases.fillProductInfoFromCache(InAppPurchases.kt:270)
        at com.adapty.purchase.InAppPurchases.access$fillProductInfoFromCache(InAppPurchases.kt:18)
        at com.adapty.purchase.InAppPurchases$queryPurchaseHistory$1.onPurchaseHistoryResponse(InAppPurchases.kt:225)
        at com.android.billingclient.api.zzj.run(com.android.billingclient:billing@@3.0.2:1)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:8167)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
@vladd-g
Copy link
Collaborator

vladd-g commented Feb 11, 2021

@krottv Thanks for the report, strange NPE in Google's billing library, we're researching why it is happening.

@krottv
Copy link
Author

krottv commented Feb 12, 2021

@vladd-g Happens on each call, so app crashes at start-up. The issue is critical. It fixes only after cleaning up app's data/cache
Also how is Adapty.getPurchaserInfo() is different from Adapty.restorePurchases? Will getPurchaserInfo restore them if before I in the app I used simple Google billing lib?

@vladd-g
Copy link
Collaborator

vladd-g commented Feb 12, 2021

@krottv Did you notice how it happened? I mean were your app crashing on start from the very first time, or it was okay initially and started crashing after specific actions? Did this crash happen again after clearing app's data?

Purchases get synced with Adapty backend under the hood on every app launch. You need to manually call restorePurchases() only if you're using Adapty in observer mode, https://docs.adapty.io/sdk/integrating-adapty-sdk/android-sdk-intro/android-sdk-observer-mode

@krottv
Copy link
Author

krottv commented Feb 13, 2021

@vladd-g
It seems that crashes started after I uploaded new version of the app on my device. And then it crashed on every start-up. After cleaning app's data the crash never happened again.
But I was able to reproduce the scenario a few times.

@vladd-g
Copy link
Collaborator

vladd-g commented Feb 14, 2021

@krottv Did both versions of the app have the same version of Adapty library?

"But I was able to reproduce the scenario a few times." - you mean after clearing data and without reinstalling? Or you installed the previous version again, then the new version, and that was the way you reproduced the crash?

@krottv
Copy link
Author

krottv commented Feb 15, 2021

@vladd-g
I reproduced by installing old version again, and updating it to the new version. The old version didn't have Adapty at all, it had https://github.com/serso/android-checkout. The new version has Adapty 0.8.4

@krottv
Copy link
Author

krottv commented Feb 20, 2021

@vladd-g
I cought a similar crash when calling Adapty.getPurchaserInfo

When I updated debug version of the app to release (both had adapty 0.8.6). Seems like it is not very hard to fix. Just introduce additional null check, it happens on your side.

 java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.json.JSONObject.optString(java.lang.String)' on a null object reference
        at com.adapty.api.entity.restore.RestoreItem.setDetails(RestoreItem.kt:3)
        at com.adapty.purchase.InAppPurchases.fillProductInfoFromCache(InAppPurchases.kt:6)
        at com.adapty.purchase.InAppPurchases.access$fillProductInfoFromCache(InAppPurchases.kt:1)
        at com.adapty.purchase.InAppPurchases$queryPurchaseHistory$1.onPurchaseHistoryResponse(InAppPurchases.kt:28)
        at a.d.a.a.q.run(com.android.billingclient:billing@@3.0.2:361)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7698)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:952)

@vladd-g
Copy link
Collaborator

vladd-g commented May 20, 2021

@krottv
It may be an obfuscation issue, please try adding -keep class com.android.billingclient.** { *; } to your proguard config

@vladd-g
Copy link
Collaborator

vladd-g commented Jun 26, 2021

@krottv could you please check this error on 1.1.0 (if still occurs, then with suggestion from my previous comment) so that I can close the issue?

@krottv
Copy link
Author

krottv commented Jul 7, 2021

The issue is gone after updaing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants