我的应用内购买应用不断崩溃

时间:2014-08-06 19:47:47

标签: android in-app-purchase

一切顺利,直到我尝试检索SkuDetails。 我已经完成了googles指南所说的最细微的细节,但仍然没有运气。

我的“thefullgame”产品已在Google Dev上设置,它也已被激活。

我已经上传了我的APK版本,因为指南告诉我......(它不需要处于beta / alpha状态吗?)

我简化的MainActivity代码:

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);        

    String base64EncodedPublicKey = "MY_KEY";

    mHelper = new IabHelper(this, base64EncodedPublicKey);

    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
       public void onIabSetupFinished(IabResult result) {
          if (!result.isSuccess()) {

            Gdx.app.log("..", "::Problem : " + result);

         }            

        List<String> additionalSkuList = new ArrayList<String>();
        additionalSkuList.add("thefullgame");

        mHelper.queryInventoryAsync(true, additionalSkuList, mQueryFinishedListener);
       }
   });

}



QueryInventoryFinishedListener 
   mQueryFinishedListener = new QueryInventoryFinishedListener() {
   public void onQueryInventoryFinished(IabResult result, Inventory inventory)   
   {
      if (result.isFailure()) {

          Gdx.app.log("..", "error : " + result );

         return;
       }

      SkuDetails myDetails = inventory.getSkuDetails("thefullgame");

      String fullgamePrice = myDetails.getPrice(); // this is the line it crashes at (line 61)


   }
};

LOGCAT:

08-06 21:41:25.988: D/AndroidRuntime(11130): Shutting down VM
08-06 21:41:25.988: W/dalvikvm(11130): threadid=1: thread exiting with uncaught exception (group=0x41744da0)
08-06 21:41:25.988: E/AndroidRuntime(11130): FATAL EXCEPTION: main
08-06 21:41:25.988: E/AndroidRuntime(11130): Process: com.blabla.blabla, PID: 11130
08-06 21:41:25.988: E/AndroidRuntime(11130): java.lang.NullPointerException
08-06 21:41:25.988: E/AndroidRuntime(11130):    at com.blabla.blabla.MainActivity$2.onQueryInventoryFinished(MainActivity.java:61)
08-06 21:41:25.988: E/AndroidRuntime(11130):    at    com.blabla.blabla.IabHelper$2$1.run(IabHelper.java:630)
08-06 21:41:25.988: E/AndroidRuntime(11130):    at android.os.Handler.handleCallback(Handler.java:733)
08-06 21:41:25.988: E/AndroidRuntime(11130):    at android.os.Handler.dispatchMessage(Handler.java:95)
08-06 21:41:25.988: E/AndroidRuntime(11130):    at android.os.Looper.loop(Looper.java:136)
08-06 21:41:25.988: E/AndroidRuntime(11130):    at android.app.ActivityThread.main(ActivityThread.java:5479)
08-06 21:41:25.988: E/AndroidRuntime(11130):    at java.lang.reflect.Method.invokeNative(Native Method)
08-06 21:41:25.988: E/AndroidRuntime(11130):    at java.lang.reflect.Method.invoke(Method.java:515)
08-06 21:41:25.988: E/AndroidRuntime(11130):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
08-06 21:41:25.988: E/AndroidRuntime(11130):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
08-06 21:41:25.988: E/AndroidRuntime(11130):    at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

将apk发布到(至少)alpha并不是一个坏主意 - 否则您往往会收到错误消息“此版本的应用程序未配置为通过Google Play结算。请查看帮助中心了解更多信息。“

不幸的是,IABHelper中有{strong> ton bugs - 其中大多数都与异步方法有关,但有些只是{{3}甚至修复了自己的错误dumb。 (在后一个示例中,修复程序已接受今天约需8个月才能被接受)。

幸运的是,大多数问题都已找到,并在have introduced bugs中进行了讨论。您需要浏览列表并自行解决。您的问题与issues queue描述的问题类似。我没有仔细看,但这样的事情可能会有所帮助:

     int queryPurchases(com.blabla.blabla.MainActivity.util.Inventory inv, String itemType) throws JSONException, RemoteException {
+        if (mDisposed) return IABHELPER_UNKNOWN_ERROR;
+        checkNotDisposed();
+        checkSetupDone("queryPurchases");
         // Query purchases

(如果您没有mDisposed,则可能没有使用最新的来源。另外请确保您拥有here。)