3

Android アプリの 1 つで、Google のアプリ内課金から在庫を簡単に取得する機能を実装しようとしていますが、次の行でエラーが発生し続けます。

mHelper.queryInventoryAsync(mGotInventoryListener);

というメッセージとともに

IabHelper がセットアップされていません。操作を実行できません: queryInventory

これがすべての IabHelper コードです。

    mHelper = new IabHelper(this, base64EncodedPublicKey);
    mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
           public void onIabSetupFinished(IabResult result) {
              if (!result.isSuccess()) {
                 // Oh noes, there was a problem.
                 Log.d(TAG, "Problem setting up In-app Billing: " + result);
              }            
                 // Hooray, IAB is fully set up!  
           }
        });
    //check to see if ads have been removed(bought)
    IabHelper.QueryInventoryFinishedListener mGotInventoryListener 
       = new IabHelper.QueryInventoryFinishedListener() {
       public void onQueryInventoryFinished(IabResult result,
          Inventory inventory) {

          if (result.isFailure()) {
            // handle error here
          }
          else {
            // does the user have the premium upgrade?
            if(inventory.hasPurchase(REMOVE_ADS)) removeAdsPurchased = true;     
            // update UI accordingly
          }
       }
    };
    mHelper.queryInventoryAsync(mGotInventoryListener);
4

3 に答える 3

-1

checkNotDisposed() メソッドを同期化するだけで、問題は解決します。これは、別のスレッドで呼び出されることがあり、メイン スレッドで設定されている可能性がある mDisposed の最新の値を常に持っているとは限らないためです。

private synchronized void checkNotDisposed()
于 2016-07-24T13:13:02.187 に答える