title: Increment TextView with button click
body: <p>thanks for the help but I'm still struggling. I did this:</p>
  
  <p><strong>Button in 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;
  </code></pre>
  
  <p><strong>Code in main (right at the end):</strong></p>
  
  <p><em>WhenI press the button the app crashes. Where specifically should I put this code?</em></p>
  
  <pre><code>Context context;    
  TextView tv;
  Button incrementer;
  
  public void incrementScore(Bundle savedInstanceState)
      {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.fragment_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));
          }
      });
  }
  </code></pre>