提问人:Ferran Negre 提问时间:2/24/2014 最后编辑:Ferran Negre 更新时间:7/2/2014 访问量:1506
IabHelper Android 错误 (NullPointerException) launchPurchaseFlow?
IabHelper Android bug (NullPointerException) launchPurchaseFlow?
问:
我使用的是 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”吗?先谢谢你。
答: 暂无答案
评论