title: Why does my findViewById() not find my Id that I have introduced in my xml code?
body: <p>I am very new to Android app development. But in one of my first projects I have come across an error. My <code>findViewById()</code> does not find an <code>Id</code> that has been introduced in the xml code. </p>
  
  <p>Here is my Java code: </p>
  
  <pre><code>package com.example.fuzzylogic;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.view.Menu;
  import android.widget.Button;
  import android.widget.TextView;
  
  public class MainActivity extends Activity {
  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.bSubtract);
      }
  
      @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;
      }
  }
  </code></pre>
  
  <p>Here is my xml code:</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=".MainActivity" &gt;
  
  &lt;TextView
      android:id="@+id/tvDisplay"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:text="Your total is 0"
      android:textSize="45dp" /&gt;
  
  &lt;Button
      android:id="@+id/bAdd"
      android:layout_width="250dp"
      android:layout_height="wrap_content"
      android:layout_below="@+id/tvDisplay"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="20dp"
      android:text="add one"
      android:textSize="25dp" /&gt;
  
  &lt;Button
      android:id="@+id/bSubtract"
      android:layout_width="250dp"
      android:layout_height="wrap_content"
      android:layout_alignLeft="@+id/bAdd"
      android:layout_below="@+id/bAdd"
      android:layout_marginTop="23dp"
      android:text="substract one"
      android:textSize="25dp" /&gt;
  
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>