title: Android application has stopped working
body: <pre><code>package com.example.tryjava;
      import android.support.v7.app.ActionBarActivity;
  
  public class MainActivity extends ActionBarActivity {
   static int counter = 0;
   static Button add;
   static Button sub;
   static TextView display;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      if (savedInstanceState == null) {
          getSupportFragmentManager().beginTransaction()
                  .add(R.id.container, new PlaceholderFragment()).commit();
      }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
  
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
      if (id == R.id.action_settings) {
          return true;
      }
      return super.onOptionsItemSelected(item);
  }
  
  /**
   * 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);
          counter = 0;
          // this is how we refer from the xml
          add = (Button)getActivity().findViewById(R.id.bADD);
          sub = (Button)getActivity().findViewById(R.id.bSUBSTRACT);
          display = (TextView)getActivity().findViewById(R.id.tvDISPLAY);
          add.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  counter ++;
                  display.setText("Your total is " + counter);
              }
          });
  
          sub.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  counter--;
                  display.setText("Your total is " + counter);
              }
          });
          return rootView;
      }
  }
  
  }
  </code></pre>
  
  <p>Its giving me a null pointer exception. I am doing this code for the second time and its not working. I looked at the error and its a nulll pointer exception. I have no idea. I have been stuck for a hile. ANy help?</p>