1

I'm doing an app which let you buy a "premium version" of it, in my cell phone it works fine, but in another cell phone when the user click a button (in an activity) this message appears:

Application unfortunately has stopped

This is the code of the onCreate() method. I guess the problem is there, but i don't know how to solve it.

 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.");

    }
};

this is the 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) 
Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
  • Refer to [this post](http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this), then [edit] with the logcat – OneCricketeer Jun 22 '16 at 23:33

1 Answers1

0

The most useful part of your error is IAB helper is not set up. Can't perform operation: queryInventory which would indicate that you haven't correctly implemented inappBillingHelper.handleActivityResult(requestCode, resultCode, data) which is required to pass on activity results back to the in app billing helper. I'm sure there will be a full example of this somewhere in the docs.

Warrick
  • 1,623
  • 1
  • 17
  • 20