v3中的NullPointerException

v3中的NullPointerException

01-23 05:32:26.747: E/AndroidRuntime(14589): java.lang.NullPointerException
01-23 05:32:26.747: E/AndroidRuntime(14589):    at com.azeandroid.sudokufree.util.IabHelper.launchPurchaseFlow(IabHelper.java:401)
01-23 05:32:26.747: E/AndroidRuntime(14589):    at com.azeandroid.sudokufree.util.IabHelper.launchPurchaseFlow(IabHelper.java:338)


在代码之后,我在论坛中看到了与“返回”相同的问题

if (listener != null) listener.onIabPurchaseFinished(r, null);


但是我的代码中有“ return”语句,但仍然给出相同的错误。

错误代码:

act.startIntentSenderForResult(pendingIntent.getIntentSender(),
                                       requestCode, new Intent(),
                                       Integer.valueOf(0), Integer.valueOf(0),
                                       Integer.valueOf(0));


完整的launchPurchaseFlow方法:

public void launchPurchaseFlow(Activity act, String sku, String itemType, int requestCode,
                    OnIabPurchaseFinishedListener listener, String extraData) {
    checkNotDisposed();
    checkSetupDone("launchPurchaseFlow");
    flagStartAsync("launchPurchaseFlow");
    IabResult result;

    if (itemType.equals(ITEM_TYPE_SUBS) && !mSubscriptionsSupported) {
        IabResult r = new IabResult(IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE,
                "Subscriptions are not available.");
        flagEndAsync();
        if (listener != null) listener.onIabPurchaseFinished(r, null);
        return;
    }

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

最佳答案

检查pendingIntent是否为空:

PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
if (pendingIntent == null)
    Log.E(TAG, "pendingIntent is null");

关于java - inAppBilling v3中的NullPointerException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21299496/

10-09 04:43