title: Getting NullPointerException when binding to a service from an activity
body: <p>I am getting a the following problem when I tried to bind from activity to a service.</p>
  
  <p>Code for Activity and this activity is a part of TabActivity</p>
  
  <pre><code>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();
          }
      };
  }
  </code></pre>
  
  <p>Now My Service Code looks like this</p>
  
  <pre><code>    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;
      }
  
  }
  </code></pre>
  
  <p>Now When Click on my BtnSubmit in my activity, I am getting the NullPointerException. I checked that I am its because in <code>myBkgService.startCounting()</code> the <code>myBkgService</code> 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.</p>