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.