IabHelper Android的错误(NullPointerException)launchPurchaseFlow?

我正在使用来自Google的应用内结算的最新版本文件。 今天,当我下载应用程序时,我的手机中出现错误(我试图重复这些步骤,但是错误不再出现)。

比方说,在我的MainActivity中,我有一个button,可以让用户购买一些应用内产品。 我的活动调用这个构造函数:

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

通过这种方式:

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

今天我得到了这个NullPointerException错误:

 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的第422行是mHelper.launch … IabHelper的第338行是构造函数。

然后在里面启动购买stream程:

386行:

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

这是在这个try-catch块内:

 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); } 

任何想法为什么? 可以是“MainActivity.this”? 先谢谢你。

Solutions Collecting From Web of "IabHelper Android的错误(NullPointerException)launchPurchaseFlow?"