Failure on findViewById on an android application
<p>So, starting with Android and Java, and I have this baffling error: The application fails with a stopped unexpectedly message when reaches a findViewByID(R.id.answer) but only if I add another one to the code.</p>

<p>The code is as below:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical" android:layout_width="match_parent"
            android:layout_height="match_parent"&gt;
  &lt;LinearLayout android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"&gt;
    &lt;TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:text="@string/site" /&gt;
    &lt;EditText android:id="@+id/site" 
             android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_weight="1"/&gt;
  &lt;/LinearLayout&gt;
  &lt;!-- 
  &lt;LinearLayout android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"&gt;
    &lt;TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:text="@string/username" /&gt;
    &lt;EditText android:id="@+id/username" 
      android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_weight="1"/&gt;
  &lt;/LinearLayout&gt;
   --&gt;
  &lt;LinearLayout android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"&gt;
    &lt;TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:text="@string/password" /&gt;
    &lt;EditText android:id="@+id/password" 
      android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_weight="1"/&gt;
  &lt;/LinearLayout&gt;
  &lt;LinearLayout android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"&gt;
    &lt;TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:text="@string/question" /&gt;
    &lt;EditText android:id="@+id/question" 
      android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_weight="1"/&gt;
  &lt;/LinearLayout&gt;
  &lt;LinearLayout android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"&gt;
    &lt;TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:text="@string/answer" /&gt;
    &lt;EditText android:id="@+id/answer" 
      android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_weight="1"/&gt;
  &lt;/LinearLayout&gt;
  &lt;Button android:id="@+id/confirm" 
          android:text="@string/confirm"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" /&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p>OnCreate method</p>

<pre><code> super.onCreate(savedInstanceState);
 setContentView(R.layout.keyedit);
 setTitle(R.string.edit_entry);
 mDbHelper = new KeyRingDbAdapter(this);
 mDbHelper.open();
 mSiteText = (EditText) findViewById(R.id.site);
 //mUsernameText = (EditText) findViewById(R.id.username);
 mPasswordText = (EditText) findViewById(R.id.password);
 mQuestionText = (EditText) findViewById(R.id.question);
 mAnswerText = (EditText) findViewById(R.id.answer);
</code></pre>

<p>So, the above works and the line <code>mAnswerText = (EditText) findViewById(R.id.answer);</code> assigns the right object to <code>mAnswerText</code>. Once I uncomment the code, that same line, that has worked before, fails. When I see the xml on the graphical layout, all appears correctly. The R file seems to be ok (I deleted it and go it regenerated, just in case).</p>

<p>Any ideas? Any more info needed?</p>

<p>EDIT: Well, awkward. Last night I got home and, when I uncommented the lines, this time it worked. I am experienced enough as programmer and I did enough checking to know that it wasn't me just uncommenting part or doing something else entirely stupid. Though it could have been something related to the fact that I am new to Eclipse as well. Not cool, as right now the error has been fixed "magically" and I am not the wiser.</p>
