我的Android应用程序在购买后崩溃。 并在logcat中显示此错误:
Unable to start receiver com.blundell.test.BillingReceiver: java.lang.NullPointerException
这是我的Logcat:
07-09 11:10:22.901: I/BillingService(3369): Starting
07-09 11:10:22.971: I/BillingService(3369): Service starting with onCreate
07-09 11:10:22.971: I/BillingService(3369): Market Billing Service Successfully Bound
07-09 11:10:23.031: I/BillingService(3369): Market Billing Service Connected.
07-09 11:10:23.111: D/OpenGLRenderer(3369): Flushing caches (mode 0)
07-09 11:10:25.031: I/BillingService(3369): isBillingSupported response was: RESULT_OK
07-09 11:10:25.031: I/BillingService(3369): requestPurchase()
07-09 11:10:25.051: I/BillingService(3369): current request is:1048018758395364016
07-09 11:10:25.051: I/BillingService(3369): REQUEST_PURCHASE Sync Response code: RESULT_OK
07-09 11:10:25.071: I/BillingService(3369): onPause())
07-09 11:10:25.181: D/OpenGLRenderer(3369): Flushing caches (mode 1)
07-09 11:10:25.181: D/OpenGLRenderer(3369): Flushing caches (mode 0)
07-09 11:10:35.151: I/BillingService(3369): Received action: com.android.vending.billing.IN_APP_NOTIFY
07-09 11:10:35.151: I/BillingService(3369): notify got id: android.test.purchased
07-09 11:10:35.151: I/BillingService(3369): getPurchaseInformation()
07-09 11:10:35.151: I/BillingService(3369): Nonce generateD: -388618139592202345
07-09 11:10:35.171: I/BillingService(3369): current request is:3124515352582500023
07-09 11:10:35.171: I/BillingService(3369): GET_PURCHASE_INFORMATION Sync Response code: RESULT_OK
07-09 11:10:35.601: I/BillingService(3369): Received action: com.android.vending.billing.RESPONSE_CODE
07-09 11:10:35.601: I/BillingService(3369): checkResponseCode got requestId: 1048018758395364016
07-09 11:10:35.601: I/BillingService(3369): checkResponseCode got responseCode: RESULT_OK
07-09 11:10:36.011: I/BillingService(3369): Received action: com.android.vending.billing.PURCHASE_STATE_CHANGED
07-09 11:10:36.011: I/BillingService(3369): purchaseStateChanged got signedData: {"nonce":-388618139592202345,"orders":[{"notificationId":"android.test.purchased","orderId":"transactionId.android.test.purchased","packageName":"org.sugarcrmclient","productId":"android.test.purchased","purchaseTime":1341812436261,"purchaseState":0}]}
07-09 11:10:36.011: I/BillingService(3369): purchaseStateChanged got signature:
07-09 11:10:36.011: I/BillingService(3369): signedData: {"nonce":-388618139592202345,"orders":[{"notificationId":"android.test.purchased","orderId":"transactionId.android.test.purchased","packageName":"org.sugarcrmclient","productId":"android.test.purchased","purchaseTime":1341812436261,"purchaseState":0}]}
07-09 11:10:36.021: D/AndroidRuntime(3369): Shutting down VM
07-09 11:10:36.021: W/dalvikvm(3369): threadid=1: thread exiting with uncaught exception (group=0x2b542210)
07-09 11:10:36.041: E/AndroidRuntime(3369): FATAL EXCEPTION: main
07-09 11:10:36.041: E/AndroidRuntime(3369): java.lang.RuntimeException: Unable to start receiver org.sugarcrmclient.market.BillingReceiver: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
07-09 11:10:36.041: E/AndroidRuntime(3369): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2146)
07-09 11:10:36.041: E/AndroidRuntime(3369): at android.app.ActivityThread.access$1500(ActivityThread.java:127)
07-09 11:10:36.041: E/AndroidRuntime(3369): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
07-09 11:10:36.041: E/AndroidRuntime(3369): at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 11:10:36.041: E/AndroidRuntime(3369): at android.os.Looper.loop(Looper.java:137)
07-09 11:10:36.041: E/AndroidRuntime(3369): at android.app.ActivityThread.main(ActivityThread.java:4441)
07-09 11:10:36.041: E/AndroidRuntime(3369): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 11:10:36.041: E/AndroidRuntime(3369): at java.lang.reflect.Method.invoke(Method.java:511)
07-09 11:10:36.041: E/AndroidRuntime(3369): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-09 11:10:36.041: E/AndroidRuntime(3369): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-09 11:10:36.041: E/AndroidRuntime(3369): at dalvik.system.NativeStart.main(Native Method)
07-09 11:10:36.041: E/AndroidRuntime(3369): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
07-09 11:10:36.041: E/AndroidRuntime(3369): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
07-09 11:10:36.041: E/AndroidRuntime(3369): at java.util.ArrayList.get(ArrayList.java:304)
07-09 11:10:36.041: E/AndroidRuntime(3369): at org.sugarcrmclient.market.BillingHelper.verifyPurchase(BillingHelper.java:250)
07-09 11:10:36.041: E/AndroidRuntime(3369): at org.sugarcrmclient.market.BillingReceiver.purchaseStateChanged(BillingReceiver.java:45)
07-09 11:10:36.041: E/AndroidRuntime(3369): at org.sugarcrmclient.market.BillingReceiver.onReceive(BillingReceiver.java:28)
07-09 11:10:36.041: E/AndroidRuntime(3369): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2139)
07-09 11:10:36.041: E/AndroidRuntime(3369): ... 10 more
答案 0 :(得分:1)
有问题的代码只针对您描述的方案进行了安全检查,您必须删除此支票:
if(purchases != null && !purchases.isEmpty()){
latestPurchase = purchases.get(0);
confirmTransaction(new String[]{latestPurchase.notificationId});
} else {
Log.d(TAG, "BillingHelper.verifyPurchase error. purchase");
}
答案 1 :(得分:0)
我可以在你的日志中看到这个IndexOutOdBoundException
,你可以检查不要访问任何不可用的数组位置。下面是突出问题。
07-09 11:10:36.041: E/AndroidRuntime(3369): java.lang.RuntimeException: Unable to start receiver org.sugarcrmclient.market.BillingReceiver: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0