title: Unable to launch an activity via a button in android, and am I reusing the AnymoteClientService correctly here?
body: <p>I am getting the following error:</p>
  
  <p>07-11 17:33:27.250: E/AndroidRuntime(1675): java.lang.RuntimeException: Unable to start activity ComponentInfo{uk.co.myapp.gtvremote/uk.co.myapp.gtvremote.SlidepuzzleActivity}: java.lang.NullPointerException</p>
  
  <p>Not sure what I have done wrong, welcome any suggestions and/or comments.</p>
  
  <p>Also you may note from the code that I am trying to reuse the AnymoteClientService. I am assuming that the way I have done it here is correct, is it?
  :</p>
  
  <p>Manifest excerpt:</p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="uk.co.myapp.gtvremote"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="15" /&gt;
  
      &lt;application
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;service android:name="com.example.google.tv.anymotelibrary.client.AnymoteClientService" &gt;
          &lt;/service&gt;
  
          &lt;activity
              android:name="com.example.google.tv.anymotelibrary.connection.PairingActivity"
              android:configChanges="orientation"
              android:label="Pairing with TV"
              android:launchMode="singleTop" /&gt;
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/title_activity_main" &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;activity
              android:name=".SlidepuzzleActivity"
              android:label="@string/title_activity_slidepuzzle" &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;/application&gt;
  
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  
      &lt;uses-feature
          android:name="android.hardware.touchscreen"
          android:required="true" /&gt;
      &lt;uses-feature
          android:name="android.hardware.wifi"
          android:required="true" /&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>MainActivity.java excerpt:</p>
  
  <pre><code>Button testButton = (Button) findViewById(R.id.testButton);
  
  ...
  
  testButton.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
  
                  Intent myIntent = new Intent(MainActivity.this, SlidepuzzleActivity.class);
  //THIS IS WHERE I THINK THE EXCEPTION IS BEING THROWN
                  MainActivity.this.startActivity(myIntent);
              }
          });
  </code></pre>
  
  <p>SlidepuzzleActivity.java:</p>
  
  <pre><code>public class SlidepuzzleActivity extends Activity implements ClientListener{
  
      private AnymoteClientService mAnymoteClientService;
      private Context mContext;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.slidepuzzle);
  
          ImageButton piece1x1 = (ImageButton) findViewById(R.id.piece1x1);
          ImageButton piece1x2 = (ImageButton) findViewById(R.id.piece1x2);
          ImageButton piece1x3 = (ImageButton) findViewById(R.id.piece1x3);
          ImageButton piece2x1 = (ImageButton) findViewById(R.id.piece2x1);
          ImageButton piece2x2 = (ImageButton) findViewById(R.id.piece2x2);
          ImageButton piece2x3 = (ImageButton) findViewById(R.id.piece2x3);
          ImageButton piece3x1 = (ImageButton) findViewById(R.id.piece3x1);
          ImageButton piece3x2 = (ImageButton) findViewById(R.id.piece3x2);
          ImageButton piece3x3 = (ImageButton) findViewById(R.id.piece3x3);
  
          Intent intent = new Intent(mContext, AnymoteClientService.class);
          bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
  
      }
  
      private ServiceConnection mConnection = new ServiceConnection() {
  
  
          /*
           * ServiceConnection listener methods.
           */
          @Override
          public void onServiceConnected(ComponentName name, IBinder service) {
  
              mAnymoteClientService = ((AnymoteClientService.AnymoteClientServiceBinder) service)
                      .getService();
              mAnymoteClientService.attachClientListener(SlidepuzzleActivity.this);
          }
  
          @Override
          public void onServiceDisconnected(ComponentName name) {
              mAnymoteClientService.detachClientListener(SlidepuzzleActivity.this);
              mAnymoteClientService = null;   
          }
  
      };
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.slidepuzzle, menu);
          return true;
      }
  
      @Override
      public void onConnected(AnymoteSender anymoteSender) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void onDisconnected() {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void onConnectionError() {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      protected void onDestroy() {
          if (mAnymoteClientService != null) {
              mAnymoteClientService.detachClientListener(this);
          }
          unbindService(mConnection);
          super.onDestroy();
      }
  
  
  }
  </code></pre>
  
  <p>Cheers</p>
  
  <p>REQUESTED STACK TRACE:</p>
  
  <pre><code>07-11 17:33:27.250: E/AndroidRuntime(1675): FATAL EXCEPTION: main
  07-11 17:33:27.250: E/AndroidRuntime(1675): java.lang.RuntimeException: Unable to start activity ComponentInfo{uk.co.myapp.gtvremote/uk.co.myapp.gtvremote.SlidepuzzleActivity}: java.lang.NullPointerException
  07-11 17:33:27.250: E/AndroidRuntime(1675):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
  07-11 17:33:27.250: E/AndroidRuntime(1675):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
  07-11 17:33:27.250: E/AndroidRuntime(1675):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
  07-11 17:33:27.250: E/AndroidRuntime(1675):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
  07-11 17:33:27.250: E/AndroidRuntime(1675):     at android.os.Handler.dispatchMessage(Handler.java:99)
  07-11 17:33:27.250: E/AndroidRuntime(1675):     at android.os.Looper.loop(Looper.java:137)
  07-11 17:33:27.250: E/AndroidRuntime(1675):     at android.app.ActivityThread.main(ActivityThread.java:4424)
  07-11 17:33:27.250: E/AndroidRuntime(1675):     at java.lang.reflect.Method.invokeNative(Native Method)
  07-11 17:33:27.250: E/AndroidRuntime(1675):     at java.lang.reflect.Method.invoke(Method.java:511)
  07-11 17:33:27.250: E/AndroidRuntime(1675):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  07-11 17:33:27.250: E/AndroidRuntime(1675):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  07-11 17:33:27.250: E/AndroidRuntime(1675):     at dalvik.system.NativeStart.main(Native Method)
  07-11 17:33:27.250: E/AndroidRuntime(1675): Caused by: java.lang.NullPointerException
  07-11 17:33:27.250: E/AndroidRuntime(1675):     at android.content.ComponentName.&lt;init&gt;(ComponentName.java:75)
  07-11 17:33:27.250: E/AndroidRuntime(1675):     at android.content.Intent.&lt;init&gt;(Intent.java:3175)
  07-11 17:33:27.250: E/AndroidRuntime(1675):     at uk.co.myapp.gtvremote.SlidepuzzleActivity.onCreate(SlidepuzzleActivity.java:39)
  07-11 17:33:27.250: E/AndroidRuntime(1675):     at android.app.Activity.performCreate(Activity.java:4465)
  07-11 17:33:27.250: E/AndroidRuntime(1675):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
  07-11 17:33:27.250: E/AndroidRuntime(1675):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
  07-11 17:33:27.250: E/AndroidRuntime(1675):     ... 11 more
  </code></pre>
  
  <p>I have marked in the SlidepuzzleActivity.java excerpt where the exception is being thrown with //THIS IS WHERE I THINK THE EXCEPTION IS BEING THROWN</p>