Search code examples
libgdxin-app-purchasegdx-pay

Gdx-pay occasional null pointer when it tries to call handlePurchase()


java.lang.NullPointerException: Attempt to invoke interface method 'void com.badlogic.gdx.pay.PurchaseObserver.handlePurchase(com.badlogic.gdx.pay.Transaction)' on a null object reference
   at com.badlogic.gdx.pay.android.googlebilling.PurchaseManagerGoogleBilling.handlePurchase(PurchaseManagerGoogleBilling.java:243)
   at com.badlogic.gdx.pay.android.googlebilling.PurchaseManagerGoogleBilling.onPurchasesUpdated(PurchaseManagerGoogleBilling.java:209)
   at com.android.billingclient.api.BillingClientImpl$1.onReceive(BillingClientImpl.java:136)
   at com.android.billingclient.api.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:303)
   at com.android.billingclient.api.LocalBroadcastManager.access$000(LocalBroadcastManager.java:44)
   at com.android.billingclient.api.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:114)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:211)
   at android.app.ActivityThread.main(ActivityThread.java:5317)
   at java.lang.reflect.Method.invoke(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)

Most times my purchases are getting completed successfully and handlePurchase() gets called on my Callback everything works fine. But occasionally I get this exception from inside of gdx-pay. It seems to indicate the observer was null.

What is the cause of this, and is there anything I can do in my code to try to prevent this issue?


Solution

  • Are you using the dispose() method and does the problem occur after you set up a new billing client? There was a bug in googlebilling implementation if you used it. See gdx-pay issue 180.

    Workaround is: Don't use dispose() and hold the billing client. Better is to use the 11.4-SNAPSHOT.