Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android bug(NullPointerException)启动PurchaseFlow?_Java_Android_Nullpointerexception_In App Billing_Android Billing - Fatal编程技术网

Java Android bug(NullPointerException)启动PurchaseFlow?

Java Android bug(NullPointerException)启动PurchaseFlow?,java,android,nullpointerexception,in-app-billing,android-billing,Java,Android,Nullpointerexception,In App Billing,Android Billing,我使用的是谷歌最新版本的应用内计费文件。今天我下载应用程序时手机出现了一个错误(我试图重复这些步骤,但错误不再出现) 比如说,在我的MainActivity中,我有一个按钮,可以让用户购买一些应用内产品。我的活动调用此构造函数: public void launchPurchaseFlow(Activity act, String sku, int requestCode, OnIabPurchaseFinishedListener listener) { launchPurchaseF

我使用的是谷歌最新版本的应用内计费文件。今天我下载应用程序时手机出现了一个错误(我试图重复这些步骤,但错误不再出现)

比如说,在我的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)
主要活动的第422行是mHelper.launch。。。IabHelper的第338行是构造函数

然后,内部LaunchPurchaseFlow:

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

知道为什么吗?可以是“主要活动。这个”?提前谢谢。

我可以确认这一点,在我的游戏机中完全相同的崩溃报告。今天,我还从queryPurchases()函数收到一个NullPointerException。谷歌IAB代码似乎是非常错误的…我目前的解决办法是捕捉任何异常,似乎不正确!你能解决这个问题吗?…面对同样的情况,有人知道吗?已经两年了,我遇到了同样的问题,onIabPurchaseFinished是空的。。。