IabHelper Android bug(NullPointerException)launchPurchaseFlow?

Fer*_*gre 8 java android nullpointerexception in-app-billing android-billing

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

让我们说在我的MainActivity中我有一个按钮,用户可以购买一些应用内商品.我的活动调用这个构造函数:

public void launchPurchaseFlow(Activity act, String sku, int requestCode, OnIabPurchaseFinishedListener listener) {
    launchPurchaseFlow(act, sku, requestCode, listener, "");
}
Run Code Online (Sandbox Code Playgroud)

通过这种方式:

mHelper.launchPurchaseFlow(MainActivity.this, SKU_UNLOCKED, RC_REQUEST,
                                mPurchaseFinishedListener, "");
Run Code Online (Sandbox Code Playgroud)

今天我得到了这个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)
Run Code Online (Sandbox Code Playgroud)

MainActivity的第422行是mHelper.launch ...... IabHelper的第338行是构造函数.

然后在launchePurchaseFlow中:

386行:

Bundle buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, itemType, extraData);
Run Code Online (Sandbox Code Playgroud)

这是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);
    }
Run Code Online (Sandbox Code Playgroud)

知道为什么吗?可以是"MainActivity.this"吗?先感谢您.