2.4.0-beta8
0.55.4
安卓
购买承诺被拒绝E_USER_CANCELLED, "Cancelled."
应用程序崩溃:
01-28 11:21:58.177 2773-2919/ D/RNIapModule: buyItemByType (type: inapp, sku: android.test.canceled, oldSku: null, prorationMode: 0) responseCode: 0(OK)
01-28 11:22:03.509 2773-2919/ D/RNIapModule: Purchase Updated Listener
01-28 11:22:03.509 2773-2919/ D/RNIapModule: responseCode: 0
--------- beginning of crash
01-28 11:22:03.510 2773-2919/ E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
Process: , PID: 2773
java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.List.get(int)' on a null object reference
at com.dooboolab.RNIap.RNIapModule$11.onPurchasesUpdated(RNIapModule.java:436)
at com.android.billingclient.api.BillingClientImpl$1.onReceiveResult(BillingClientImpl.java:151)
at android.os.ResultReceiver$MyRunnable.run(ResultReceiver.java:50)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:192)
at java.lang.Thread.run(Thread.java:764)
真实设备
android.test.canceled
onPurchasesUpdated
,在第436行Purchase purchase = purchases.get(0);
处引发NPE,因为purchases
是@Nullable
和 null
而responseCode
为0。感谢解决方案的问题。 @johnmartel如果您已经知道如何解决问题,希望您给我们PR
。
@hyochan我正在研究这个问题,我将尽快提交PR。 问题是lib严重缺乏测试,很难确定我没有破坏其他任何东西。
@johnmartel是的。 我一直希望实现一些测试模块,但是目前,我总是没时间使用😿。 发布之前,我们必须自己检查运行时。
像这样检查purchases
是否null
怎么样?
PurchasesUpdatedListener purchasesUpdatedListener = new PurchasesUpdatedListener() {
<strong i="8">@Override</strong>
public void onPurchasesUpdated(int responseCode, <strong i="9">@Nullable</strong> List<Purchase> purchases) {
Log.d(TAG, "Purchase Updated Listener");
Log.d(TAG, "responseCode: " + responseCode);
if (responseCode != BillingClient.BillingResponse.OK) {
rejectPromisesWithBillingError(PROMISE_BUY_ITEM, responseCode);
return;
}
+ if (purchases == null) {
+ rejectPromisesWithBillingError(PROMISE_BUY_ITEM , responseCode);
+ return;
+ }
Purchase purchase = purchases.get(0);
// ...
嘿,看来最近没有任何活动在此问题上。 问题是否已解决,还是仍然需要社区的关注? 如果没有其他活动,则可能已关闭此问题。 您也可以将此问题标记为“供讨论”或“良好的第一期”,我将其保留为开放状态。 感谢你的贡献。
最有用的评论
@johnmartel是的。 我一直希望实现一些测试模块,但是目前,我总是没时间使用😿。 发布之前,我们必须自己检查运行时。