title: Android: Logcat shows error on (.setOnClickListener)
body: <p>when i run this code, its not working and the catlog sends me to that line:
  "add.setOnClickListener(new View.OnClickListener() {"</p>
  
  <p>here is my code:</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
  
      int counter;
      Button add, sub;
      TextView display; 
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          counter =0;
          add = (Button) findViewById(R.id.Badd);
          sub = (Button) findViewById(R.id.Bsub);
          display = (TextView) findViewById(R.id.TVmain);
  
  
  
          add.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  counter++;
                  display.setText("Your Total is: " + counter);
              }
          });
  </code></pre>
  
  <p>activity_main.xml:</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="com.example.pluseonecalculator.MainActivity"
      tools:ignore="MergeRootFrame" /&gt;
  </code></pre>
  
  <p>this is the logcat:</p>
  
  <blockquote>
    <p>03-27 23:14:27.150: I/Process(408): Sending signal. PID: 408 SIG: 9
        03-27 23:27:01.070: D/AndroidRuntime(420): Shutting down VM
        03-27 23:27:01.070: W/dalvikvm(420): threadid=1: thread exiting with uncaught exception (group=0x40015560)
        03-27 23:27:01.090: E/AndroidRuntime(420): FATAL EXCEPTION: main
        03-27 23:27:01.090: E/AndroidRuntime(420): java.lang.RuntimeException: Unable to start activity
    ComponentInfo{com.example.pluseonecalculator/com.example.pluseonecalculator.MainActivity}:
    java.lang.NullPointerException
        03-27 23:27:01.090: E/AndroidRuntime(420):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
        03-27 23:27:01.090: E/AndroidRuntime(420):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
        03-27 23:27:01.090: E/AndroidRuntime(420):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
        03-27 23:27:01.090: E/AndroidRuntime(420):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
        03-27 23:27:01.090: E/AndroidRuntime(420):    at android.os.Handler.dispatchMessage(Handler.java:99)
        03-27 23:27:01.090: E/AndroidRuntime(420):    at android.os.Looper.loop(Looper.java:123)
        03-27 23:27:01.090: E/AndroidRuntime(420):    at android.app.ActivityThread.main(ActivityThread.java:3683)
        03-27 23:27:01.090: E/AndroidRuntime(420):    at java.lang.reflect.Method.invokeNative(Native Method)
        03-27 23:27:01.090: E/AndroidRuntime(420):    at java.lang.reflect.Method.invoke(Method.java:507)
        03-27 23:27:01.090: E/AndroidRuntime(420):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
        03-27 23:27:01.090: E/AndroidRuntime(420):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
        03-27 23:27:01.090: E/AndroidRuntime(420):    at dalvik.system.NativeStart.main(Native Method)
        03-27 23:27:01.090: E/AndroidRuntime(420): Caused by: java.lang.NullPointerException
        03-27 23:27:01.090: E/AndroidRuntime(420):    at com.example.pluseonecalculator.MainActivity.onCreate(MainActivity.java:34)
        03-27 23:27:01.090: E/AndroidRuntime(420):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
        03-27 23:27:01.090: E/AndroidRuntime(420):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
        03-27 23:27:01.090: E/AndroidRuntime(420):    ... 11 more</p>
  </blockquote>