title: FindViewById returning null?
body: <p>I am trying to populate a <code>listView</code> from an array. However, when I try and find the listview in my java code, the findViewById function returns null.</p>
  
  <p>Here is my XML:</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:background="@drawable/androidbg_dark"
      tools:context=".DiaryActivity" &gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical" &gt;
  
          &lt;ListView
              android:id="@+id/lstAppts"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_weight="5"
              android:textColor="#FFFFFF" &gt;&lt;/ListView&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:orientation="horizontal"
              android:layout_weight="1" 
              android:layout_height="64dp"&gt;
  
              &lt;Button
                  android:id="@+id/btnOther"
                  style="?android:attr/buttonBarButtonStyle"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:layout_margin="2dip"
                  android:layout_weight="1"
                  android:background="@drawable/menu_button"
                  android:onClick="newAppointment"
                  android:textColor="#FFFFFF" /&gt;
  
              &lt;Button
                  android:id="@+id/btnOther2"
                  style="?android:attr/buttonBarButtonStyle"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:layout_margin="2dip"
                  android:layout_weight="1"
                  android:background="@drawable/menu_button"
                  android:onClick="newAppointment"
                  android:textColor="#FFFFFF" /&gt;
  
              &lt;Button
                  android:id="@+id/btnNewAppt"
                  style="?android:attr/buttonBarButtonStyle"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:layout_margin="2dip"
                  android:layout_weight="1"
                  android:background="@drawable/menu_button"
                  android:onClick="newAppointment"
                  android:text="@string/newappt"
                  android:textColor="#FFFFFF" /&gt;
          &lt;/LinearLayout&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And here is the offending code:</p>
  
  <pre><code>ListView lstAppts = (ListView) findViewById(R.id.lstAppts);
  String[] data = { "Appointment 1", "Appointment 2", "Appointment 3" };
  
  ArrayAdapter adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, data);
  lstAppts.setAdapter(adapter);
  </code></pre>
  
  <p>To my knowledge, I am referencing the listview correctly. It is named 'lstAppts' in my XML, and in the <code>findViewById</code> function, I find it using <code>R.id.lstAppts</code>. However when I debug the code with breakpoints, I can clearly see the the lstAppts object is <code>null</code>. Why is this?</p>