我在我的开发者控制台中创建了5个项目(产品),但是当使用QueryInventory获取项目的SkuDetails时,它只返回4个项目,因此在尝试获取非详细信息时会出现Null Pointer Exception - 提取产品。
此外,有时它只返回其中一个项目,有时它不会返回任何项目。
Google有时会退回一些(而非全部)产品吗?
我希望有人可以帮我找出原因:
在这次运行中,我没有得到item4
在mHelper.startSetup内部
additionalSkuList.add(SKU_item1);
additionalSkuList.add(SKU_item2);
additionalSkuList.add(SKU_item3);
additionalSkuList.add(SKU_item4); // this one is missing in the response
additionalSkuList.add(SKU_item5);
mHelper.queryInventoryAsync(true, additionalSkuList,mQueryFinishedListener);
在queryInventoryListener中:
String item1Price =inventory.getSkuDetails(SKU_item1).getPrice();
String item2Price =inventory.getSkuDetails(SKU_item2).getPrice();
String item3Price =inventory.getSkuDetails(SKU_item3).getPrice();
String item4Price =inventory.getSkuDetails(SKU_item4).getPrice(); //Null Pointer Exc. HERE
String item5Price =inventory.getSkuDetails(SKU_item5).getPrice();
并且所有五个项目在Google Play开发者控制台中都显示为有效。
这是Logcat输出
05-19 19:33:49.048: D/BillingTest(23534): Starting IAB setup.
05-19 19:33:49.048: D/IabHelper(23534): Starting in-app billing setup.
05-19 19:33:49.058: D/IabHelper(23534): Billing service connected.
05-19 19:33:49.058: D/IabHelper(23534): Checking for in-app billing 3 support.
05-19 19:33:49.068: D/IabHelper(23534): In-app billing version 3 supported for com.billingtest.billingtest2
05-19 19:33:49.068: D/IabHelper(23534): Subscriptions AVAILABLE.
05-19 19:33:49.068: I/BillingTest(23534): IAB Setup finished.
05-19 19:33:49.068: I/BillingTest(23534): Setup successful. Querying inventory.
05-19 19:33:49.068: I/BillingTest(23534): Starting to query
05-19 19:33:49.068: D/IabHelper(23534): Starting async operation: refresh inventory
05-19 19:33:49.068: D/IabHelper(23534): Querying owned items, item type: inapp
05-19 19:33:49.068: D/IabHelper(23534): Package name: com.billingtest.billingtest2
05-19 19:33:49.068: D/IabHelper(23534): Calling getPurchases with continuation token: null
05-19 19:33:49.078: D/IabHelper(23534): Owned items response: 0
05-19 19:33:49.078: D/IabHelper(23534): Continuation token: null
05-19 19:33:49.078: D/IabHelper(23534): Querying SKU details.
05-19 19:33:49.078: D/IabHelper(23534): query SKU: item1
05-19 19:33:49.078: D/IabHelper(23534): query SKU: item2
05-19 19:33:49.078: D/IabHelper(23534): query SKU: item3
05-19 19:33:49.078: D/IabHelper(23534): query SKU: item4
05-19 19:33:49.078: D/IabHelper(23534): query SKU: item5
05-19 19:19:23.755: D/IabHelper(21969): Got sku details: SkuDetails:{"title":"item1 (BillingTest)","price":"£0.59","type":"inapp","description":"item1desc","price_amount_micros":990000,"price_currency_code":"USD","productId":"item1"}
05-19 19:19:23.755: D/IabHelper(21969): Got sku details: SkuDetails:{"title":"item2(BillingTest)","price":"£0.59","type":"inapp","description":"item2desc","price_amount_micros":990000,"price_currency_code":"USD","productId":"item2"}
05-19 19:19:23.765: D/IabHelper(21969): Got sku details: SkuDetails:{"title":"item3(BillingTest)","price":"£0.59","type":"inapp","description":"item3desc","price_amount_micros":990000,"price_currency_code":"USD","productId":"item3"}
05-19 19:19:23.765: D/IabHelper(21969): Got sku details: SkuDetails:{"title":"item5(BillingTest)","price":"£1.78","type":"inapp","description":"item5desc","price_amount_micros":2990000,"price_currency_code":"USD","productId":"item5"}
05-19 19:19:23.765: D/IabHelper(21969): Querying owned items, item type: subs
05-19 19:19:23.765: D/IabHelper(21969): Package name: com.billingtest.billingtest2
05-19 19:19:23.765: D/IabHelper(21969): Calling getPurchases with continuation token: null
05-19 19:19:23.775: D/IabHelper(21969): Owned items response: 0
05-19 19:19:23.775: D/IabHelper(21969): Continuation token: null
05-19 19:19:23.775: D/IabHelper(21969): Querying SKU details.
05-19 19:19:23.775: D/IabHelper(21969): query SKU: item1
05-19 19:19:23.775: D/IabHelper(21969): query SKU: item2
05-19 19:19:23.775: D/IabHelper(21969): query SKU: item3
05-19 19:19:23.775: D/IabHelper(21969): query SKU: item4
05-19 19:19:23.775: D/IabHelper(21969): query SKU: item5
05-19 19:19:23.785: D/OpenGLRenderer(21969): Enabling debug mode 0
05-19 19:19:23.805: D/IabHelper(21969): Ending async operation: refresh inventory
05-19 19:19:23.885: I/BillingTest(21969): Inside QueryInventoryFinished Listener
05-19 19:19:23.885: D/BillingTest(21969): Query inventory was successful.
05-19 19:19:23.885: D/AndroidRuntime(21969): Shutting down VM
05-19 19:19:23.885: W/dalvikvm(21969): threadid=1: thread exiting with uncaught exception (group=0x415e9ba8)
05-19 19:19:23.885: E/AndroidRuntime(21969): FATAL EXCEPTION: main
05-19 19:19:23.885: E/AndroidRuntime(21969): Process: com.billingtest.billingtest2, PID: 21969
05-19 19:19:23.885: E/AndroidRuntime(21969): java.lang.NullPointerException
05-19 19:19:23.885: E/AndroidRuntime(21969): at com.billingtest.billingtest2.MainActivity$1.onQueryInventoryFinished(MainActivity.java:250)
05-19 19:19:23.885: E/AndroidRuntime(21969): at com.billingtest.billingtest2.util.IabHelper$2$1.run(IabHelper.java:633)
05-19 19:19:23.885: E/AndroidRuntime(21969): at android.os.Handler.handleCallback(Handler.java:733)
05-19 19:19:23.885: E/AndroidRuntime(21969): at android.os.Handler.dispatchMessage(Handler.java:95)
05-19 19:19:23.885: E/AndroidRuntime(21969): at android.os.Looper.loop(Looper.java:136)
05-19 19:19:23.885: E/AndroidRuntime(21969): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-19 19:19:23.885: E/AndroidRuntime(21969): at java.lang.reflect.Method.invokeNative(Native Method)
05-19 19:19:23.885: E/AndroidRuntime(21969): at java.lang.reflect.Method.invoke(Method.java:515)
05-19 19:19:23.885: E/AndroidRuntime(21969): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-19 19:19:23.885: E/AndroidRuntime(21969): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-19 19:19:23.885: E/AndroidRuntime(21969): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:3)
每当您向应用内商品列表中添加新商品时,通常需要15分钟到3小时才能完全传播到所有Google Play服务器。发布您的应用或更新的APK同样如此。不幸的是,您只需要耐心等待,并让服务器有时间处理您的请求。