Java InAppv3中的NullPointerException
在代码发布后,我在论坛上看到了“return”的同样问题Java InAppv3中的NullPointerException,java,android,in-app-billing,Java,Android,In App Billing,在代码发布后,我在论坛上看到了“return”的同样问题 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
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)
但我的代码中有“return”语句,但仍然给出相同的错误
出现错误的代码:
if (listener != null) listener.onIabPurchaseFinished(r, null);
完全启动PurchaseFlow方法:
act.startIntentSenderForResult(pendingIntent.getIntentSender(),
requestCode, new Intent(),
Integer.valueOf(0), Integer.valueOf(0),
Integer.valueOf(0));
检查
pendingent
是否为空:
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);
}
}
还要检查getIntentSender()是否为null。比如:
PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
if (pendingIntent == null)
Log.E(TAG, "pendingIntent is null");
请发布整个
launchPurchaseFlow
I发布了整个方法(已编辑),它也不为空。我将从一开始就从不同的来源给每个人写信,似乎它不想工作
if (pendingIntent.getINtentSender()!=null)
act.startIntentSenderForResult(pendingIntent.getIntentSender(),
requestCode, new Intent(),
Integer.valueOf(0), Integer.valueOf(0),
Integer.valueOf(0));