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 7996905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:49:38+00:00 2026-06-04T14:49:38+00:00

I’m trying to implement in-app billing to my application. I’m reading the guide on

  • 0

I’m trying to implement in-app billing to my application.

I’m reading the guide on developer.android.com, looking at their example application.

I started to write basic methods for check if In-App billing is supported, but when i try to call sendBillingRequest i receive the following error:

05-17 14:23:30.479: W/System.err(15332): java.lang.NullPointerException
05-17 14:23:30.489: W/System.err(15332):    at resistorcalc.main.billing.BillingService.checkBilling(BillingService.java:63)
05-17 14:23:30.489: W/System.err(15332):    at resistorcalc.main.SupportusActivity.onCreate(SupportusActivity.java:24)
05-17 14:23:30.499: W/System.err(15332):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-17 14:23:30.509: W/System.err(15332):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
05-17 14:23:30.509: W/System.err(15332):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
05-17 14:23:30.519: W/System.err(15332):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-17 14:23:30.529: W/System.err(15332):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-17 14:23:30.539: W/System.err(15332):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-17 14:23:30.539: W/System.err(15332):    at android.os.Looper.loop(Looper.java:130)
05-17 14:23:30.549: W/System.err(15332):    at android.app.ActivityThread.main(ActivityThread.java:3687)
05-17 14:23:30.549: W/System.err(15332):    at java.lang.reflect.Method.invokeNative(Native Method)
05-17 14:23:30.549: W/System.err(15332):    at java.lang.reflect.Method.invoke(Method.java:507)
05-17 14:23:30.549: W/System.err(15332):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
05-17 14:23:30.559: W/System.err(15332):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
05-17 14:23:30.559: W/System.err(15332):    at dalvik.system.NativeStart.main(Native Method)

The billingService Class is:

package resistorcalc.main.billing;

import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

import com.android.vending.billing.IMarketBillingService;

public class BillingService extends Service implements ServiceConnection {


private static final String TAG = "BillingService";
private IMarketBillingService mService;

public BillingService(){
    super();
}

@Override
public void onCreate() {        
    super.onCreate();
    try {
        Log.i(TAG, "Service starting with onCreate");            
        boolean bindResult = bindService(new Intent("com.android.vending.billing.MarketBillingService.BIND"), this, Context.BIND_AUTO_CREATE);
        if(bindResult){
            Log.i(TAG,"Market Billing Service Successfully Bound");
        } else {
            Log.e(TAG,"Market Billing Service could not be bound.");            
        }
    } catch (SecurityException e){
                Log.e(TAG,"Market Billing Service could not be bound. SecurityException: "+e);                 
    }    
}

public void setContext(Context context) {
    attachBaseContext(context);
}

/**
  * The Android system calls this when we are connected to the MarketBillingService.
  */
public void onServiceConnected(ComponentName name, IBinder service) {
    Log.i(TAG, "MarketBillingService connected.");
    mService = IMarketBillingService.Stub.asInterface(service);
}

protected Bundle makeRequestBundle(String method) {
    Bundle request = new Bundle();
    request.putString(BillingConst.BILLING_REQUEST_METHOD, method);
    request.putInt(BillingConst.BILLING_REQUEST_API_VERSION, 1);
    request.putString(BillingConst.BILLING_PACKAGE_NAME, getPackageName());
    return request;
}

public boolean checkBilling(){      
    try {
        Bundle request = makeRequestBundle("CHECK_BILLING_SUPPORTED");
        Bundle response = mService.sendBillingRequest(request);
        int code = response.getInt("RESPONSE_CODE");
        if(code==0){
            return true;
        } else {
            return false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.err.print(e.getMessage());
        return false;
    }
}

public void onServiceDisconnected(ComponentName arg0) {
    // TODO Auto-generated method stub

}

@Override
public IBinder onBind(Intent arg0) {
    // TODO Auto-generated method stub
    return null;
}

}

The exception occur on that line:

Bundle response = mService.sendBillingRequest(request);

This happens because the mService variable is null. The mService variable is initialized on that method:

public void onServiceConnected(ComponentName name, IBinder service) {
    Log.i(TAG, "MarketBillingService connected.");
    mService = IMarketBillingService.Stub.asInterface(service);
}

(as written in the that guide: http://developer.android.com/guide/market/billing/billing_integrate.html#billing-service)
The problem is that onServiceConnected is never called.

The activity that launch the service:

    public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.supportus);
    mBillingService = new BillingService();
    mBillingService.setContext(this);
    Intent intent = new Intent();
            intent.setClass(this, BillingService.class);        
    startService(intent);
    if(mBillingService.checkBilling()){
        Toast.makeText(this, "TRUE", Toast.LENGTH_SHORT);
    } else {
        Toast.makeText(this, "FALSE", Toast.LENGTH_SHORT);
    }
}

I cannot understand what is the problem. Why the onCreate and onServiceConnected method aren’t called? Looking at the service lifceycle the BillingService onCreate method should be called with a startService.
Where did I wrong

  • 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-04T14:49:40+00:00Added an answer on June 4, 2026 at 2:49 pm

    FInally i found the solution on that problem. And it was my fault.

    The error was in the manifest, in fact i declared in the service as

        <service android:name=".BillingService" />
    

    But the BillingService class was in a subpackage (resistorcalc.main.billing). Then i replaced the line with:

        <service android:name=".billing.BillingService" />
    

    And the service started to work.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.