2016-06-22 58 views
1

我正在做一個應用程序,它可以讓你購買它的「高級版本」,在我的手機中它工作正常,但在另一個手機當用戶點擊一個按鈕時(在一個活動中)此消息出現:我有我的android應用程序的幾個問題,如何解決它?

應用不幸已經停止

這是onCreate()方法的代碼。我想問題在那裏,但我不知道如何解決它。

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_selector); 
    Bundle s = getIntent().getExtras(); 
    int x = s.getInt("day"); 
    int y = s.getInt("month"); 
    int z = s.getInt("year"); 
    String base64EncodedPublicKey = "MY GOOGLE ID" 
    mHelper = new IabHelper(this, base64EncodedPublicKey); 


    // compute your public key and store it in 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); 
      } 

      Log.d(TAG, "Setup successful. Querying inventory."); 

      try { 
       mHelper.queryInventoryAsync(false,mGotInventoryListener); 
      } catch (IabHelper.IabAsyncInProgressException e) { 
       e.printStackTrace(); 
      } 
      // Hooray, IAB is fully set up! 
     } 
    }); 




} 

IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() { 
    public void onQueryInventoryFinished(IabResult result, 
             Inventory inventory) { 
     Log.d(TAG, "Query inventory finished."); 
     if (result.isFailure()) { 
      alert("Failed to query inventory: " + result); 
      return; 
     } 

     Log.d(TAG, "Query inventory was successful."); 

     // Do we have the premium upgrade? 
     mIsPremium = inventory.hasPurchase(SKU_PREMIUM); 
     if(mIsPremium) 
     { 
      updateUi(); 
     } 
     Log.d(TAG, "User is " + (mIsPremium ? "PREMIUM" : "NOT PREMIUM")); 

     Log.d(TAG, "Initial inventory query finished; enabling main UI."); 

    } 
}; 

這是logat:

com.skope.sebastian.horoscopo E/IabHelper: In-app billing error: Illegal state for operation (queryInventory): IAB helper is not set up. 
com.skope.sebastian.horoscopo D/AndroidRuntime: Shutting down VM 
com.skope.sebastian.horoscopo E/AndroidRuntime: FATAL EXCEPTION: main 
Process: com.skope.sebastian.horoscopo, PID: 6709 
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.skope.sebastian.horoscopo/botones.skope.Horoscopo.selector}: 
java.lang.IllegalStateException: IAB helper is not set up. Can't perform operation: queryInventory 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
Caused by: java.lang.IllegalStateException: IAB helper is not set up. Can't perform operation: queryInventory 
at botones.skope.Horoscopo.util.IabHelper.checkSetupDone(IabHelper.java:861) 
at botones.skope.Horoscopo.util.IabHelper.queryInventoryAsync(IabHelper.java:691) 
at botones.skope.Horoscopo.util.IabHelper.queryInventoryAsync(IabHelper.java:721) 
at botones.skope.Horoscopo.selector$1.onIabSetupFinished(selector.java:59) 
at botones.skope.Horoscopo.util.IabHelper.startSetup(IabHelper.java:306) 
at botones.skope.Horoscopo.selector.onCreate(selector.java:49) 
at android.app.Activity.performCreate(Activity.java:6237) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)  
at android.app.ActivityThread.-wrap11(ActivityThread.java)  
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)  
at android.os.Handler.dispatchMessage(Handler.java:102)  
at android.os.Looper.loop(Looper.java:148)  
at android.app.ActivityThread.main(ActivityThread.java:5417)  
at java.lang.reflect.Method.invoke(Native Method)  
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)  
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  
+0

請參考[這篇文章](http://stackoverflow.com/questions/23353173/uncomfort-myapp-has-stopped-how-can-i-solve-this),然後[編輯]與logcat –

回答

0

你的錯誤的最有用的部分是IAB helper is not set up. Can't perform operation: queryInventory這將表明你沒有正確實施這是需要傳遞活動inappBillingHelper.handleActivityResult(requestCode, resultCode, data)結果返回給在應用程序結算幫手。我確信在文檔的某個地方會有一個完整的例子。

相關問題