Android login page throwing NullPointerException
<p>I am trying to create a login page.  My research has given me the following code, but I keep getting a java.lang.NullPointerException at line 29.  I have tried to research the answer myself but have just ended up very confused.  Can someone help me understand what I am missing please?</p>

<p>LOGINTESTERACTIVITY class</p>

<pre><code>package com.b00512756.Logintester;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


public class LogintesterActivity extends Activity {

EditText txtUserName;
EditText txtPassword;
Button btnLogin;
Button btnCancel;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        txtUserName=(EditText)this.findViewById(R.id.txtUname);
        txtPassword=(EditText)this.findViewById(R.id.txtPwd);
        btnLogin=(Button)this.findViewById(R.id.btnLogin);
        btnLogin.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub

if((txtUserName.getText().toString()).equals(txtPassword.getText().toString())){
        Toast.makeText(LogintesterActivity.this, "Login Successful",Toast.LENGTH_LONG).show();
       } else{
        Toast.makeText(LogintesterActivity.this, "Invalid Login",Toast.LENGTH_LONG).show();
       }

}
});       
    }
} 
</code></pre>

<p>main.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
    &lt;TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="1"&gt;

&lt;TableRow&gt;
&lt;TextView 
android:text="User Name: " 
android:id="@+id/TextView01" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"&gt;
&lt;/TextView&gt;

&lt;EditText 
android:text="" 
android:id="@+id/txtUname" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"&gt;
&lt;/EditText&gt;
&lt;/TableRow&gt;


&lt;TableRow&gt;
&lt;TextView 
android:text="Password: " 
android:id="@+id/TextView02" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"&gt;
&lt;/TextView&gt;


&lt;EditText 
android:text="" 
android:id="@+id/txtPwd" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:password="true"&gt;
&lt;/EditText&gt;
&lt;/TableRow&gt;


&lt;TableRow&gt;
&lt;Button
android:text="Cancel" 
android:id="@+id/btnCancel" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"&gt;
&lt;/Button&gt;


&lt;Button
android:text="Login" 
android:id="@+id/btnLogin" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"&gt;
&lt;/Button&gt;


&lt;/TableRow&gt;


&lt;/TableLayout&gt;
</code></pre>

<p>Manifest.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.b00512756.Logintester"
      android:versionCode="1"
      android:versionName="1.0"&gt;
    &lt;uses-sdk android:minSdkVersion="8" /&gt;

    &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
        &lt;activity android:name=".LogintesterActivity"
                  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;/application&gt;
&lt;/manifest&gt;
</code></pre>

<p>Error Log:</p>

<pre><code>04-29 15:36:41.570: WARN/dalvikvm(690): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-29 15:36:41.590: ERROR/AndroidRuntime(690): FATAL EXCEPTION: main
04-29 15:36:41.590: ERROR/AndroidRuntime(690): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.b00512756.Logintester/com.b00512756.Logintester.LogintesterActivity}: java.lang.NullPointerException
04-29 15:36:41.590: ERROR/AndroidRuntime(690):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-29 15:36:41.590: ERROR/AndroidRuntime(690):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-29 15:36:41.590: ERROR/AndroidRuntime(690):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-29 15:36:41.590: ERROR/AndroidRuntime(690):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-29 15:36:41.590: ERROR/AndroidRuntime(690):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-29 15:36:41.590: ERROR/AndroidRuntime(690):     at android.os.Looper.loop(Looper.java:123)
04-29 15:36:41.590: ERROR/AndroidRuntime(690):     at android.app.ActivityThread.main(ActivityThread.java:4627)
04-29 15:36:41.590: ERROR/AndroidRuntime(690):     at java.lang.reflect.Method.invokeNative(Native Method)
04-29 15:36:41.590: ERROR/AndroidRuntime(690):     at java.lang.reflect.Method.invoke(Method.java:521)
04-29 15:36:41.590: ERROR/AndroidRuntime(690):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-29 15:36:41.590: ERROR/AndroidRuntime(690):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-29 15:36:41.590: ERROR/AndroidRuntime(690):     at dalvik.system.NativeStart.main(Native Method)
04-29 15:36:41.590: ERROR/AndroidRuntime(690): Caused by: java.lang.NullPointerException
04-29 15:36:41.590: ERROR/AndroidRuntime(690):     at com.b00512756.Logintester.LogintesterActivity.onCreate(LogintesterActivity.java:29)
04-29 15:36:41.590: ERROR/AndroidRuntime(690):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-29 15:36:41.590: ERROR/AndroidRuntime(690):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
</code></pre>

<p>Many thanks,
Richy</p>
