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

  • Home
  • SEARCH
  • 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 7583049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:35:18+00:00 2026-05-30T18:35:18+00:00

I am getting a the following problem when I tried to bind from activity

  • 0

I am getting a the following problem when I tried to bind from activity to a service.

Code for Activity and this activity is a part of TabActivity

public class SettingsActivity extends Activity{

private BkgService myBkgService;
Button BtnSubmit;

public void onCreate(Bundle savedInstanceState) {

setContentView(R.layout.settings);
BtnSubmit = (Button)findViewById(R.id.XmlBtnSubmit);
BtnSubmit.setOnClickListener(onSubmit);

Intent bindIntent = new Intent(this, BkgService.class);
bindService(bindIntent, serviceConncetion, Context.BIND_AUTO_CREATE);
}


private ServiceConnection serviceConncetion = new ServiceConnection() {

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            myBkgService = ((BkgService.MyBinder)service).getService();
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            myBkgService = null;
        }
    };

private OnClickListener onSubmit = new OnClickListener() {

        @Override
        public void onClick(View v) {
            myBkgService.startCounting();
        }
    };
}

Now My Service Code looks like this

    public class BkgService extends Service{
    private IBinder mBinder;
    private int i;


    public void onCreate() {
           super.onCreate();
    }

    @Override
    public IBinder onBind(Intent arg0) {
            return mBinder;
    }

    public class MyBinder extends Binder {
    BkgService getService() {
            return BkgService.this;
        }
    }

    public int startCounting(){
        return i=i+1;
    }

}

Now When Click on my BtnSubmit in my activity, I am getting the NullPointerException. I checked that I am its because in myBkgService.startCounting() the myBkgService is null.I am unable to find out why I am getting this null pointer. Is my activity is not properly bound to the service. Please suggest some solution to this. I am stuck up here.

  • 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-05-30T18:35:19+00:00Added an answer on May 30, 2026 at 6:35 pm

    Make sure you declare your service in your AndroidManifest.xml. If you don’t, then the call to bindService will return false.

    I also notice that you did not initialize your mBinder, something like the following is needed in your BkgService.

    private IBinder mBinder = new MyBinder();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem getting a change event to register with the following code:
Am getting following error message on calling WCF service: The formatter threw an exception
I am getting Following Exception while configuring the Connection Pool in Tomcat This is
I am getting following error each time I tried to select database. The database
I am getting following error: COM object that has been separated from its underlying
When I run following code: public ActionResult Complete() { try { VeriTabanDataContext db =
Problem: I'm getting a thrown error from javax.net.ssl.SSLHandshakeException (see attached picture) Is it possible
I keep getting the following error message when I run my code in debug.
I have the following code and I'm getting crazy with calling an auto_increment id
When ever i tried to launch my eclipse debug(for server side code) i'm getting

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.