I have an In-App Billing setup for the first time using the new v3 API. It works correctly on my devices, but I have received many error reports from other users.
One of them:
java.lang.IllegalStateException: IAB helper is not set up. Can't perform operation: queryInventory at my.package.util.iab.IabHelper.checkSetupDone(IabHelper.java:673) at my.package.util.iab.IabHelper.queryInventory(IabHelper.java:462) at my.package.util.iab.IabHelper$2.run(IabHelper.java:521) at java.lang.Thread.run(Thread.java:1019)
And one more:
java.lang.NullPointerException at my.package.activities.MainActivity$4.onIabSetupFinished(MainActivity.java:159) at my.package.util.iab.IabHelper$1.onServiceConnected(IabHelper.java:242)
My activity implementation follows the example of Google code (all reference classes are intact from the example):
IabHelper mHelper; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //... mHelper = new IabHelper(this, IAB_PUBLIC_KEY); mHelper.enableDebugLogging(true); mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { public void onIabSetupFinished(IabResult result) { if (!result.isSuccess()) { // Oh noes, there was a problem. return; } // Hooray, IAB is fully set up. Now, let get an inventory of // stuff we own. mHelper.queryInventoryAsync(mGotInventoryListener); //***(1)*** } }); } // Listener that called when we finish querying the items we own IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() { public void onQueryInventoryFinished(IabResult result, Inventory inventory) { if (!result.isFailure()) { if (inventory.hasPurchase(SoundsGlobals.IAB_SKU_PREMIUM)){ //we are premium, do things } } else{ //oops } } }; @Override protected void onDestroy() { if (mHelper != null) { mHelper.dispose(); mHelper = null; } super.onDestroy(); }
I assume both errors come from a line labeled as ***(1)***
What is the cause of these errors? If I call queryInventoryAsync only inside onIabSetupFinished , how is it possible that mHelper is null or that mHelper not configured?
Does anyone know about this solution?
android in-app-billing
Ereza Dec 25 2018-12-12T00: 00Z
source share