title: Click Listener causing unable to start activity nullpointer exception
body: <p>I've been struggling with this issue all day in a larger project. I wrote a test app to rule out it being caused by my data objects etc. But I am getting the same results.  Everything in this app is more or less the boilerplate provided by android studio and examples taken from the developer documentation. the min SDK is 4.0 and I am compiling it with 4.3.</p>
  
  <pre><code>    package com.testapp.testapp;
  
          import android.app.Activity;
          import android.app.ActionBar;
          import android.app.Fragment;
      import android.os.Bundle;
      import android.view.LayoutInflater;
      import android.view.Menu;
      import android.view.MenuItem;
      import android.view.View;
      import android.view.ViewGroup;
      import android.os.Build;
      import android.widget.Button;
      import android.widget.TextView;
  
      public class MainActivity extends Activity {
      TextView MyTextview;
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              if (savedInstanceState == null) {
                  getFragmentManager().beginTransaction()
                          .add(R.id.container, new PlaceholderFragment())
                          .commit();
              }
              Button MyButton = (Button)findViewById(R.id.mybutton);
              MyTextview = (TextView)findViewById(R.id.tv);
              final View.OnClickListener Click = new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      switch(v.getId()) {
                          case R.id.mybutton:
                              MyTextview.setText("Test");
                          break;
                      }
                  }
              };
              MyButton.setOnClickListener(Click);
          }
          /**
           * A placeholder fragment containing a simple view.
           */
          public static class PlaceholderFragment extends Fragment {
  
              public PlaceholderFragment() {
              }
  
              @Override
              public View onCreateView(LayoutInflater inflater, ViewGroup container,
                      Bundle savedInstanceState) {
                  View rootView = inflater.inflate(R.layout.fragment_main, container, false);
                  return rootView;
              }
          }
  
      }
  </code></pre>
  
  <p>fragment_main.xml
      </p>
  
  <pre><code>    &lt;TextView
          android:text="@string/hello_world"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/tv"/&gt;
      &lt;Button
          android:layout_height="75dp"
          android:layout_width="fill_parent"
          android:id="@+id/mybutton"
       /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Stacktrace</p>
  
  <pre><code>11-04 15:47:08.396  21228-21228/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.testapp.testapp/com.testapp.testapp.MainActivity}: java.lang.NullPointerException
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2336)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2386)
              at android.app.ActivityThread.access$600(ActivityThread.java:150)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1266)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:137)
              at android.app.ActivityThread.main(ActivityThread.java:5256)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:525)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
              at dalvik.system.NativeStart.main(Native Method)
       Caused by: java.lang.NullPointerException
              at com.testapp.testapp.MainActivity.onCreate(MainActivity.java:39)
              at android.app.Activity.performCreate(Activity.java:5133)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2290)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2386)
              at android.app.ActivityThread.access$600(ActivityThread.java:150)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1266)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:137)
              at android.app.ActivityThread.main(ActivityThread.java:5256)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:525)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>