Android IabHelper (NullPointerException) launchPurchaseFlow error?

I use the latest versions of billing files in an application from Google. Today I received an error message on my phone when downloading the application (I tried to repeat the steps, but the error no longer appears).

Let's say that in my MainActivity I have a button where the user offers to buy some product in the application. My activity calls this constructor:

public void launchPurchaseFlow(Activity act, String sku, int requestCode, OnIabPurchaseFinishedListener listener) { launchPurchaseFlow(act, sku, requestCode, listener, ""); } 

Thus:

 mHelper.launchPurchaseFlow(MainActivity.this, SKU_UNLOCKED, RC_REQUEST, mPurchaseFinishedListener, ""); 

And today I got this NullPointerException error:

 java.lang.NullPointerException at xxx.xxx.xxxxx.util.IabHelper.launchPurchaseFlow(IabHelper:386) at xxx.xxx.xxxxx.util.IabHelper.launchPurchaseFlow(IabHelper:338) at xxx.xxx.xxxxx.MainActivity$6.onClick(MainActivity:422) 

MainActivity line 422 is mHelper.launch ... IabHelper line 338 is the constructor.

Then inside launchchePurchaseFlow:

Line 386:

 Bundle buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, itemType, extraData); 

What is inside this try-catch block:

 try { logDebug("Constructing buy intent for " + sku + ", item type: " + itemType); Bundle buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, itemType, extraData); int response = getResponseCodeFromBundle(buyIntentBundle); if (response != BILLING_RESPONSE_RESULT_OK) { logError("Unable to buy item, Error response: " + getResponseDesc(response)); flagEndAsync(); result = new IabResult(response, "Unable to buy item"); if (listener != null) listener.onIabPurchaseFinished(result, null); return; } PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT); logDebug("Launching buy intent for " + sku + ". Request code: " + requestCode); mRequestCode = requestCode; mPurchaseListener = listener; mPurchasingItemType = itemType; act.startIntentSenderForResult(pendingIntent.getIntentSender(), requestCode, new Intent(), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0)); } catch (SendIntentException e) { logError("SendIntentException while launching purchase flow for sku " + sku); e.printStackTrace(); flagEndAsync(); result = new IabResult(IABHELPER_SEND_INTENT_FAILED, "Failed to send intent."); if (listener != null) listener.onIabPurchaseFinished(result, null); } catch (RemoteException e) { logError("RemoteException while launching purchase flow for sku " + sku); e.printStackTrace(); flagEndAsync(); result = new IabResult(IABHELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow"); if (listener != null) listener.onIabPurchaseFinished(result, null); } 

Any idea on why? Could be "MainActivity.this"? Thank you in advance.

+8
java android nullpointerexception in-app-billing android-billing
source share

No one has answered this question yet.

See related questions:

3606
Close / hide Android soft keyboard
3295
Why is the Android emulator so slow? How can we speed up Android emulator development?
3288
Correct use cases for Android UserManager.isUserAGoat ()?
2609
Is there a unique identifier for an Android device?
2510
How to keep Android activity state by saving instance state?
2097
Is there a way to run Python on Android?
1858
"Debug certificate expired" error in Android Eclipse plugins
1844
What is "Context" on Android?
0
in-app billing error could not buy error response to element 5 developer error
0
Android bug in android google play billing subscription it does not return purchase data and signature data?

All Articles