我的android应用程序有几个问题,如何解决?

时间:2016-06-22 23:29:56

标签: android in-app-billing

我正在做一个让你购买它的“高级版”的应用程序,在我的手机中它工作正常,但在另一部手机中当用户点击按钮(在活动中)时会出现以下消息:< / p>

  

应用程序很遗憾已停止

这是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) 

1 个答案:

答案 0 :(得分:0)

您的错误中最有用的部分是IAB helper is not set up. Can't perform operation: queryInventory,这表示您未正确实施inappBillingHelper.handleActivityResult(requestCode, resultCode, data),这需要将活动结果传递回应用内结算助手。我相信在文档的某个地方会有一个完整的例子。