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

  • Home
  • SEARCH
  • 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

Im trying to create a simple input box with form validation, but im not
I have been trying to create a simple application that will let the user
I'm trying to create a simple modeless dialog box which I'm creating from my
I am trying to create a simple modal dialog in XCode 4. I have
I'm trying to create simple script that subscribes a user to a company calendar.
Im trying to create a simple pan and zoom app using silverlight 4, but
I'm trying to create a simple widget to retrieve a users feeds, I have
I am new so this is probably simple but I have looked everywhere and
I am trying to create a simple dialog in MFC using Visual C++. My
I am trying to create a simple list view with a search box at

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.