title: Android bindService throws NullPointerException
body: <p>I worked through several tutorials to build my first bindService in Android but I keep on getting the same NullPointerException I don't understand. My last example is very simple...</p>
  
  <p>MyActivity.java:</p>
  
  <pre><code>package de.123team.myapplication;
  
  import android.app.Activity; import android.content.ComponentName; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.IBinder; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView;
  
  public class MyActivity extends Activity {
  
      // Connection
      MySumService mService;
      boolean mBound;
  
      ServiceConnection mConnection = new ServiceConnection() {
  
          @Override
          public void onServiceDisconnected(ComponentName name) {
              mBound = false;
              //mService = null;
          }
  
          @Override
          public void onServiceConnected(ComponentName name, IBinder service) {
              mBound = true;
              MySumService.LocalBinder binder = (MySumService.LocalBinder)service;
              mService = binder.getService();
          }
  
      };
  
  
      @Override
      protected void onStart() {
          super.onStart();
      }
  
  
      @Override
      protected void onStop() {
          super.onStop();
  
          if (mBound) {
              mService.unbindService(mConnection);
              mBound = false;
          }
      }
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_my);
  
  
          TextView tvResult = (TextView)findViewById(R.id.tvResult);
          //tvResult.setText("Test123");
  
          Intent i = new Intent(this, MySumService.class);
          bindService(i, mConnection, BIND_AUTO_CREATE); 
  
          int r = mService.sum(1, 2);
          tvResult.setText(new String().valueOf(r));
      } }
  </code></pre>
  
  <p>MySumService.java:</p>
  
  <pre><code>package de.123team.myapplication;
  
  import android.app.Service;
  import android.content.Intent;
  import android.os.Binder;
  import android.os.IBinder;
  
  public class MySumService extends Service {
  
  
      private IBinder mBinder = new LocalBinder();
  
  
      @Override
      public IBinder onBind(Intent intent) {
          // TODO: Return the communication channel to the service.
          return mBinder;
      }
  
  
      public int sum(int a, int b) {
          return 666;
      }
  
  
      public class LocalBinder extends Binder {
          public MySumService getService() {
              return MySumService.this;
          }
      }
  
  
  }
  </code></pre>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="de.proteam.myapplication" &gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
  
          &lt;activity
              android:name=".MyActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
          &lt;service
              android:name=".MySumService"
              android:enabled="true"
              android:exported="true" &gt;
          &lt;/service&gt;
  
      &lt;/application&gt; &lt;/manifest&gt; 
  </code></pre>
  
  <p>And the depressing logCat I'm looking at for hours... </p>
  
  <pre><code>08-25 10:19:59.809    5107-5107/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
      java.lang.RuntimeException: Unable to start activity ComponentInfo{de.123team.myapplication/de.123team.myapplication.MyActivity}: java.lang.NullPointerException
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
              at android.app.ActivityThread.access$600(ActivityThread.java:141)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:137)
              at android.app.ActivityThread.main(ActivityThread.java:5041)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
              at dalvik.system.NativeStart.main(Native Method)
       Caused by: java.lang.NullPointerException
              at de.123team.myapplication.MyActivity.onCreate(MyActivity.java:86)
              at android.app.Activity.performCreate(Activity.java:5104)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
              at android.app.ActivityThread.access$600(ActivityThread.java:141)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:137)
              at android.app.ActivityThread.main(ActivityThread.java:5041)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:511)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>