IabHelper Android bug(NullPointerException)launchPurchaseFlow?

时间:2014-02-24 11:52:17

标签: 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, "");
}

这样:

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行是构造函数。

然后在launchePurchaseFlow:

里面

第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" ?提前谢谢。

0 个答案:

没有答案