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 3998744
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:33:55+00:00 2026-05-20T07:33:55+00:00

I am trying to create a simple dialog box to allow my user to

  • 0

I am trying to create a simple dialog box to allow my user to create a new user. I have the layout the way i need it but for some reason when i click the Create button it throws an exception. I have tried various way to accomplish this but i must be leaving something out. I am now on day two of this error and I am all out of options. I have ever re-wrote the code twice and went over with a fine tooth comb.

here is what i have so far:

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final HttpClient httpclient = new DefaultHttpClient();

    //new user button, work in progress
    Button newuser = (Button) findViewById(R.id.new_user);
    newuser.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            final Dialog createU = new Dialog(MainActivity.this);



            createU.setContentView(R.layout.newuser);
            createU.setTitle("Create User");

            Button create = (Button) createU.findViewById(R.id.createUsr);
            Button cancel = (Button) createU.findViewById(R.id.cancel);



            create.setOnClickListener(new View.OnClickListener() {//creates the user

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    String usr = null, pass = null;
                    EditText userU = (EditText) findViewById(R.id.createUsr);
                    EditText passU = (EditText) findViewById(R.id.cancel);

                    if(userU.getText()!= null){//throws ERROR/AndroidRuntime(9937): java.lang.NullPointerException

                        usr = userU.getText().toString();
                    }
                    if(passU.getText()!=null){
                        pass = passU.getText().toString();
                    }


                    Toast toast = Toast.makeText(getApplicationContext(), "User: " + usr + ", Pass: " + pass, Toast.LENGTH_SHORT);
                    toast.show();
                }
            });
            cancel.setOnClickListener(new View.OnClickListener() {//closes dialog

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    createU.hide();
                }
            });
            createU.show();
        }
    });
   }
 }
<?xml version="1.0" encoding="utf-8"?>

<EditText android:id="@+id/usrTxt" android:layout_height="wrap_content"
    android:layout_width="match_parent" android:maxLines="1" android:hint="Username"
    android:text="2"></EditText>
<EditText android:id="@+id/pasTxt" android:layout_height="wrap_content"
    android:layout_width="match_parent" android:layout_below="@id/usrTxt"
    android:inputType="textPassword" android:maxLines="1" android:hint="Password"
    android:text="2"></EditText>
<Button android:layout_height="wrap_content"
    android:layout_alignParentLeft="true" android:layout_width="wrap_content"
    android:layout_below="@+id/pasTxt" android:text="Create" android:id="@+id/createUsr"></Button>
<Button android:layout_height="wrap_content"
    android:layout_width="wrap_content" android:id="@+id/cancel"
    android:layout_alignParentRight="true" android:text="Cencel"
    android:layout_below="@+id/pasTxt"></Button>

  • 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-05-20T07:33:56+00:00Added an answer on May 20, 2026 at 7:33 am

    Do not initialize strings with null values

    avoid String usr = null, pass = null; . Hope that will help.

    Update:

    Change the above line causing error as

    if (!userU.getText().toString().equals("")) {
    

    Update2

    Change the Edittext initialization lines as below

      EditText userU = (EditText) findViewById(R.id.usrTxt);                     
      EditText passU = (EditText) findViewById(R.id.pasTxt); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to postgreSQL and I have a simple question: I'm trying to create
I am trying to create simple user registration form. I have an index.html file
I have been trying to create a simple application that will let the user
I am trying to create a simple dialog in MFC using Visual C++. My
I'm trying to create a simple BaSH-like grammar on ANTLRv3 but haven't been able
I'm trying to come up with a simple and efficient way to create a
I am trying to create a simple modal dialog on the iPad, in either
I'm trying to create a simple JQuery UI modal dialog populated with a loaded
I'm trying to show a simple dialog like this: if (!aboutDialog) aboutDialog = new
Im trying to create a simple callback using blocks. I have a MainViewController which

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.