Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9184193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:59:06+00:00 2026-06-17T18:59:06+00:00

I have been recently trying to implement in app billing on a game I

  • 0

I have been recently trying to implement in app billing on a game I am working on, but I get a NullPointerException and I just can’t see why.

BuyActivity.java:

package com.liamw.games.whatami;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.provider.Settings.Secure;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.liamw.games.whatami.util.IabHelper;
import com.liamw.games.whatami.util.IabResult;
import com.liamw.games.whatami.util.Inventory;
import com.liamw.games.whatami.util.Purchase;

public class BuyActivity extends Activity {

    String key, androidid;
    IabHelper mHelper;
    Button fifty;
    ProgressDialog wait;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // DONE Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_buy);

        fifty = (Button) findViewById(R.id.b50hints);
        androidid = Secure.getString(BuyActivity.this.getContentResolver(),
                Secure.ANDROID_ID);

        final ProgressDialog wait = new ProgressDialog(this);
        wait.setTitle("Updating...");
        wait.setMessage("Please wait while the details are loaded...");
        wait.setCancelable(false);
        wait.show();

        key = "xxxxx";
        mHelper = new IabHelper(this, key);

        mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
            public void onIabSetupFinished(IabResult result) {
                if (!result.isSuccess()) {
                    // Oh noes, there was a problem.
                    Log.d("What Am I - IAB",
                            "Problem setting up In-app Billing: " + result);
                }
                // Hooray, IAB is fully set up!

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

                mHelper.queryInventoryAsync(true, additionalSkuList,
                        mQueryFinishedListener);

            }
        });

        fifty.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                mHelper.launchPurchaseFlow(BuyActivity.this, "50hints", 10001,
                        mPurchaseFinishedListener, androidid);
                fifty.setEnabled(false);

            }
        });

    }

    IabHelper.QueryInventoryFinishedListener mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
        public void onQueryInventoryFinished(IabResult result,
                Inventory inventory) {
            if (result.isFailure()) {
                // handle error
                return;
            }

            String fiftyhintscost = inventory.getSkuDetails("50hints").getPrice();

            fifty.setText("50 Hints: " + fiftyhintscost);
            wait.dismiss();
            // update the UI
        }
    };

    IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
        public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
            if (result.isFailure()) {
                Log.d("What Am I? IAB", "Error purchasing: " + result);
                return;
            } else if (purchase.getSku().equals("50hints")
                    && purchase.getDeveloperPayload().equals(androidid)) {
                // consume the gas and update the UI
                mHelper.consumeAsync(purchase, mConsumeFinishedListener);
            }
            fifty.setEnabled(true);
        }
    };

    IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() {
        public void onConsumeFinished(Purchase purchase, IabResult result) {
            if (result.isSuccess()) {
                // provision the in-app purchase to the user
                // (for example, credit 50 gold coins to player's character)
                Toast.makeText(BuyActivity.this,
                        "Purchase Successful - Crediting!", Toast.LENGTH_LONG)
                        .show();
            } else {
                // handle error
            }
        }
    };

    @Override
    public void onDestroy() {
        if (mHelper != null)
            mHelper.dispose();
        mHelper = null;
        super.onDestroy();
    }
}

Logcat:

01-18 19:12:45.829: E/AndroidRuntime(16849): FATAL EXCEPTION: main
01-18 19:12:45.829: E/AndroidRuntime(16849): java.lang.NullPointerException
01-18 19:12:45.829: E/AndroidRuntime(16849):    at com.liamw.games.whatami.BuyActivity$1.onQueryInventoryFinished(BuyActivity.java:87)
01-18 19:12:45.829: E/AndroidRuntime(16849):    at com.liamw.games.whatami.util.IabHelper$2$1.run(IabHelper.java:533)
01-18 19:12:45.829: E/AndroidRuntime(16849):    at android.os.Handler.handleCallback(Handler.java:725)
01-18 19:12:45.829: E/AndroidRuntime(16849):    at android.os.Handler.dispatchMessage(Handler.java:92)
01-18 19:12:45.829: E/AndroidRuntime(16849):    at android.os.Looper.loop(Looper.java:137)
01-18 19:12:45.829: E/AndroidRuntime(16849):    at android.app.ActivityThread.main(ActivityThread.java:5039)
01-18 19:12:45.829: E/AndroidRuntime(16849):    at java.lang.reflect.Method.invokeNative(Native Method)
01-18 19:12:45.829: E/AndroidRuntime(16849):    at java.lang.reflect.Method.invoke(Method.java:511)
01-18 19:12:45.829: E/AndroidRuntime(16849):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-18 19:12:45.829: E/AndroidRuntime(16849):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-18 19:12:45.829: E/AndroidRuntime(16849):    at dalvik.system.NativeStart.main(Native Method)

Line 87:

String fiftyhintscost = inventory.getSkuDetails("50hints").getPrice();

Please help me locate the source of the NullPointer and tell me how to fix it…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:59:08+00:00Added an answer on June 17, 2026 at 6:59 pm

    Turns out that you can only use letters in the SKU…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently been trying to implement my first Android game using a similar
I've been recently trying to connect to a hosted MySQL using Java but can't
Recently I have been trying to make changes so I can do builds through
Has anyone managed to use core-plot from wax? I have been trying recently, but
I have been trying to implement the new scope features that were recently added
I've just recently been trying to get into JSTL and I'm experiencing some problems
Recently I have been working with a SQL Server database and I was trying
Recently, I have been trying to get the built-in Windows 7 narrator/screen reader to
I have recently been trying to upgrade my app form Rails 2.3.8 to newly-releases
I have recently been trying to get into the habit of using MVVM design

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.