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

The Archive Base Latest Questions

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

I am trying to use the new window and attaching edittext to get name

  • 0

I am trying to use the new window and attaching edittext to get name from the user. It just always fail when it hits the line ” “name”.getText().toString()”

Here is my main

public class chatter extends Activity {

private String name;


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


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
    case R.id.setNameMenu:
        setname();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

public void setname()
{
    final EditText textNameInput = (EditText) findViewById(R.id.nameBox);
    /*Dialog dialog = new Dialog(chatter.this);
    dialog.setTitle("This is my custom dialog box");
    */
    setContentView(R.layout.custom_dialog);
    //dialog.setCancelable(true);
    Button button = (Button) findViewById(R.id.submitNameButton);
    button.setOnClickListener(new OnClickListener() {
    @Override
        public void onClick(View v) {
            //String nameinput = textNameInput.getText().toString();
            **//this is where it does not work**
        **Editable debug1 = textNameInput.getText();**  
        String nameinput = debug1.toString();
            name = nameinput;
            finish();
        }
    });
}
}

Here is the layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<TextView
    android:id="@+id/dialogueText"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="please input your name:"
    />
<EditText 
    android:id="@+id/nameBox"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"       
    android:layout_below="@+id/dialogueText" />
<Button
    android:text=" Set "
    android:id="@+id/submitNameButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/nameBox"
    android:layout_alignParentRight="true"
    />
</RelativeLayout>

I am new to programing in android, please kindly explain what went wrong.

  • 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-20T05:33:18+00:00Added an answer on May 20, 2026 at 5:33 am

    Since you haven’t posted a stacktrace I’m guessing at the error, but I’m thinking you are getting a NullPointerException as textNameInput is null. You also haven’t said which of the two layouts that you refer to in your code is the one that you have listed, but I’m guessing its R.layout.custom_dialog? If so, then your call to findViewById(R.id.nameBox) will return null as it happens before you have loaded the layout that contains R.id.nameBox. Move the call to after you load the layout.

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

Sidebar

Related Questions

I am new to R and trying to use the animation package. From the
I am trying to use the new DATETIMEOFFSET data type in SQL 2008 but
I am trying to use nunits new way of exception handling but I am
I'm trying to use the new OpenCV 2.0 API in MS Visual C++ 2008
I am trying to use the new immutable OptionParser in the Scala scopt 2.0.1
I'm trying to use the new ASP.NET Web API to do the following: A
I've been trying to use the new jquery-ui, and all but the resizable function
I'm trying use self-signed certificate (c#): X509Certificate2 cert = new X509Certificate2( Server.MapPath(~/App_Data/myhost.pfx), pass); on
I have a project which I am trying to use in another new project,
Trying to use this code to connect the AD PrincipalContext context = new PrincipalContext(ContextType.Domain,

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.