Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7856101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:35:31+00:00 2026-06-02T20:35:31+00:00

I am trying to create a login page. My research has given me the

  • 0

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?

LOGINTESTERACTIVITY class

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();
       }

}
});       
    }
} 

main.xml

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

<TableRow>
<TextView 
android:text="User Name: " 
android:id="@+id/TextView01" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content">
</TextView>

<EditText 
android:text="" 
android:id="@+id/txtUname" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content">
</EditText>
</TableRow>


<TableRow>
<TextView 
android:text="Password: " 
android:id="@+id/TextView02" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content">
</TextView>


<EditText 
android:text="" 
android:id="@+id/txtPwd" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:password="true">
</EditText>
</TableRow>


<TableRow>
<Button
android:text="Cancel" 
android:id="@+id/btnCancel" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content">
</Button>


<Button
android:text="Login" 
android:id="@+id/btnLogin" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content">
</Button>


</TableRow>


</TableLayout>

Manifest.xml

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

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".LogintesterActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

Error Log:

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)

Many thanks,
Richy

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:35:33+00:00Added an answer on June 2, 2026 at 8:35 pm

    Run it in a debugger. Set a breakpoint at line 29, and inspect the values of your variables at that point. Work out which one is null that shouldn’t be, then look back to where it was set, and try to work out why it might have been set to null.

    Also, try commenting out line 29, and see what happens.

    My suspicion is your layout isn’t loading correctly for some reason, but I’m not sure what that reason would be. Might be helpful for you to see what it looks like.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a simple login page in ASP.NET C# but am
I am trying to create a login page that will send the user to
Im trying to create a iPhone Objective C login page using PHP/MySQL to authenticate.
I'm trying to create a Login page, not worrying about actually logging in yet,
I am trying to create a login page for some sites that I manage.
I'm new to cakePHP. I'm trying to create a login page. I was able
I'm trying to create a login aspx page. What am I doing wrong here?
I'm trying to create a login system like http://us.battle.net/en/ . The page is fully
I'm trying to create a simply login page. I want validation on that page
I m trying to create a new register and login page. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.