title: Android onclickEventListener exception
body: <p>I have the following code</p>
  
  <pre><code>public class StartingPoint extends ActionBarActivity {
  
  int counter;
  Button add, substract;
  TextView display;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_starting_point);
  
      counter = 0;
      add = (Button) findViewById(R.id.btn_add);
      substract = (Button) findViewById(R.id.btn_subscract);
      display = (TextView) findViewById(R.id.txt_display);
  
      if (savedInstanceState == null) {
          getSupportFragmentManager().beginTransaction()
                  .add(R.id.container, new PlaceholderFragment()).commit();
      }
  
      add.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              counter++;
              display.setText("Your total is " + counter);
          }
      });
  }       
  </code></pre>
  
  <p>Im getting all kinds of exceptions when trying to run it:</p>
  
  <pre><code>05-11 21:23:47.604: E/AndroidRuntime(1944): java.lang.RuntimeException: Unable to start activity ComponentInfo{l.r.thenewboston/l.r.thenewboston.StartingPoint}: java.lang.NullPointerException
  05-11 21:23:47.604: E/AndroidRuntime(1944):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
  </code></pre>
  
  <p>What is wrong here ?</p>
  
  <p>The activity starting point layout</p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/container"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="l.r.thenewboston.StartingPoint"
      tools:ignore="MergeRootFrame" /&gt;
  </code></pre>
  
  <p>and the fregment_starting_point layout</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context="l.r.thenewboston.StartingPoint$PlaceholderFragment" &gt;
  
  &lt;TextView
      android:id="@+id/txt_display"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/total_text"
      android:textSize="44sp"
      android:layout_gravity="center" 
      android:gravity="center"/&gt;
  
  &lt;Button
      android:id="@+id/btn_add"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignLeft="@+id/txt_display"
      android:layout_below="@+id/txt_display"
      android:layout_marginTop="19dp"
      android:textSize="18sp"
      android:text="@string/add_one" /&gt;
  
  &lt;Button
      android:id="@+id/btn_subscract"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignBaseline="@+id/btn_add"
      android:layout_alignBottom="@+id/btn_add"
      android:layout_alignRight="@+id/txt_display"
      android:text="@string/minus_one"
      android:textSize="18sp" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>public static class PlaceholderFragment extends Fragment {</p>
  
  <pre><code>public PlaceholderFragment() {
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_starting_point,
              container, false);
      return rootView;
  }
  </code></pre>
  
  <p>}</p>