title: Android: Intent setClass causes NullPointer exception
body: <p>I want use Intent from TcpClient go to PreCamera. It 's causes java.lang.NullPointer Exception.</p>
  
  <pre><code>Intent intent = new Intent();
  Log.v("Pic", "context");
  intent.setClass(TcpClient.this, PreCamera.class);
  Log.v("Pic", "ok");
  this.mContext.startActivity(intent);
  </code></pre>
  
  <p>this is TcpClient construct:</p>
  
  <pre><code>public TcpClient(Context context) {
      mContext = context;
  }
  </code></pre>
  
  <p>This is the Exception information:</p>
  
  <pre><code>12-08 10:56:53.515: V/Pic(2579): context
  12-08 10:56:53.519: W/dalvikvm(2579): threadid=13: thread exiting with uncaught exception (group=0x40020ac0)
  12-08 10:56:53.519: E/AndroidRuntime(2579): FATAL EXCEPTION: Thread-14
  12-08 10:56:53.519: E/AndroidRuntime(2579): java.lang.NullPointerException
  12-08 10:56:53.519: E/AndroidRuntime(2579):     at android.content.ContextWrapper.getPackageName(ContextWrapper.java:120)
  12-08 10:56:53.519: E/AndroidRuntime(2579):     at android.content.ComponentName.&lt;init&gt;(ComponentName.java:75)
  12-08 10:56:53.519: E/AndroidRuntime(2579):     at android.content.Intent.setClass(Intent.java:4920)
  12-08 10:56:53.519: E/AndroidRuntime(2579):     at com.Image.Collect.TcpClient.takePic(TcpClient.java:330)
  12-08 10:56:53.519: E/AndroidRuntime(2579):     at com.Image.Collect.TcpClient.commandExecute(TcpClient.java:467)
  12-08 10:56:53.519: E/AndroidRuntime(2579):     at com.Image.Collect.TcpClient.receive(TcpClient.java:278)
  12-08 10:56:53.519: E/AndroidRuntime(2579):     at com.Image.Collect.TcpClient.talk(TcpClient.java:179)
  12-08 10:56:53.519: E/AndroidRuntime(2579):     at com.Image.Collect.InfoCollect$6.run(InfoCollect.java:303)
  12-08 10:56:53.539: E/InfoCollect(2579): onPause
  </code></pre>
  
  <p>this is some AndroidMainfest.xml information:</p>
  
  <pre><code> &lt;activity android:name=".TcpClient"
                   ... (other info)
          &lt;/activity&gt;
   &lt;activity android:name=".PreCamera"
                  ... (other info)
          &lt;/activity&gt;
  </code></pre>
  
  <p>The API is level 8.</p>
  
  <p>When I try this:</p>
  
  <pre><code>Intent intent = new Intent(TcpClient.this, PreCamera.class);
  </code></pre>
  
  <p>it causes:</p>
  
  <pre><code>12-08 11:31:45.221: W/dalvikvm(2805): threadid=13: thread exiting with uncaught exception (group=0x40020ac0)
  12-08 11:31:45.229: E/AndroidRuntime(2805): FATAL EXCEPTION: Thread-14
  12-08 11:31:45.229: E/AndroidRuntime(2805): java.lang.NullPointerException
  12-08 11:31:45.229: E/AndroidRuntime(2805):     at android.content.ContextWrapper.getPackageName(ContextWrapper.java:120)
  12-08 11:31:45.229: E/AndroidRuntime(2805):     at android.content.ComponentName.&lt;init&gt;(ComponentName.java:75)
  </code></pre>
  
  <p>I see someone say this is because I init mContext is too early, It should be init after OnCreate() method or later. But how to init after this method? I'm a beginner of Android Dev.</p>
  
  <p>TcpClient is extends Activity. I use:</p>
  
  <pre><code>mContext = this;
  Intent intent = new Intent(TcpClient.this, PreCamera.class); 
  </code></pre>
  
  <p>it is not woking well.</p>