title: Increment value in TextView by pressing button
body: <p>I want to be able to increment the value in my textview by pressing a button. I tried the code below, but when I press the button the app crashes.</p>
  
  <p><strong>XML</strong></p>
  
  <pre><code>&lt;Button
      android:id="@+id/button1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="43dp"
      android:background="@android:color/white"
      android:onClick="incrementScore"
      android:text="@string/player" /&gt;
  
  &lt;TextView
      android:id="@+id/textView1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_below="@+id/button1"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="42dp"
      android:textColor="@android:color/white"
      android:text="@string/player_score" /&gt;
  </code></pre>
  
  <p><strong>The button is on the main screen. Here is the incrementScore method</strong></p>
  
  <pre><code>public void incrementScore(View view)
  {
      Intent intent = new Intent(this, Increment.class);
  
      startActivity(intent);
  }
  </code></pre>
  
  <p><strong>Increment class onCreate</strong></p>
  
  <pre><code>Context context;    
  TextView tv;
  Button incrementer;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.activity_home);
      tv=(TextView)findViewById(R.id.textView1);
      incrementer=(Button)findViewById(R.id.button1);
      context=this;
  
      incrementer.setOnClickListener(new View.OnClickListener() 
      {
  
          @Override
          public void onClick(View v) 
          {
              String present_value_string = tv.getText().toString();
              int present_value_int = Integer.parseInt(present_value_string);
              present_value_int++;
  
              tv.setText(String.valueOf(present_value_int));          
          }
      });
  
      if (savedInstanceState == null) {
          getSupportFragmentManager().beginTransaction()
                  .add(R.id.container, new PlaceholderFragment()).commit();
      }
  }
  </code></pre>
  
  <p><strong>Android Manifest</strong></p>
  
  <pre><code>&lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name="com.example.experiment.Home"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity
          android:name="com.example.experiment.Increment"
          android:label="@string/title_activity_increment" &gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p><strong>Log Cat</strong></p>
  
  <pre><code>04-25 15:32:56.664: D/libEGL(27300): loaded /system/lib/egl/libEGL_mali.so
  04-25 15:32:56.674: D/libEGL(27300): loaded /system/lib/egl/libGLESv1_CM_mali.so
  04-25 15:32:56.674: D/libEGL(27300): loaded /system/lib/egl/libGLESv2_mali.so
  04-25 15:32:56.694: D/OpenGLRenderer(27300): Enabling debug mode 0
  04-25 15:33:01.260: D/AndroidRuntime(27300): Shutting down VM
  04-25 15:33:01.260: W/dalvikvm(27300): threadid=1: thread exiting with uncaught exception (group=0x4112e2a0)
  04-25 15:33:01.260: E/AndroidRuntime(27300): FATAL EXCEPTION: main
  04-25 15:33:01.260: E/AndroidRuntime(27300): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.experiment/com.example.experiment.Increment}: java.lang.NullPointerException
  04-25 15:33:01.260: E/AndroidRuntime(27300):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2092)
  04-25 15:33:01.260: E/AndroidRuntime(27300):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)
  04-25 15:33:01.260: E/AndroidRuntime(27300):    at android.app.ActivityThread.access$700(ActivityThread.java:134)
  04-25 15:33:01.260: E/AndroidRuntime(27300):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1218)
  04-25 15:33:01.260: E/AndroidRuntime(27300):    at android.os.Handler.dispatchMessage(Handler.java:99)
  04-25 15:33:01.260: E/AndroidRuntime(27300):    at android.os.Looper.loop(Looper.java:137)
  04-25 15:33:01.260: E/AndroidRuntime(27300):    at android.app.ActivityThread.main(ActivityThread.java:4867)
  04-25 15:33:01.260: E/AndroidRuntime(27300):    at java.lang.reflect.Method.invokeNative(Native Method)
  04-25 15:33:01.260: E/AndroidRuntime(27300):    at java.lang.reflect.Method.invoke(Method.java:511)
  04-25 15:33:01.260: E/AndroidRuntime(27300):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
  04-25 15:33:01.260: E/AndroidRuntime(27300):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
  04-25 15:33:01.260: E/AndroidRuntime(27300):    at dalvik.system.NativeStart.main(Native Method)
  04-25 15:33:01.260: E/AndroidRuntime(27300): Caused by: java.lang.NullPointerException
  04-25 15:33:01.260: E/AndroidRuntime(27300):    at com.example.experiment.Increment.onCreate(Increment.java:29)
  04-25 15:33:01.260: E/AndroidRuntime(27300):    at android.app.Activity.performCreate(Activity.java:5047)
  04-25 15:33:01.260: E/AndroidRuntime(27300):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
  04-25 15:33:01.260: E/AndroidRuntime(27300):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)
  04-25 15:33:01.260: E/AndroidRuntime(27300):    ... 11 more
  04-25 15:33:01.320: D/dalvikvm(27300): GC_CONCURRENT freed 181K, 10% free 9551K/10567K, paused 13ms+2ms, total 53ms
  </code></pre>
  
  <p>Please help</p>