Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to convert Edit text to String, got error with "name".getText().toString() line
    primarykey
    data
    text
    <p>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"<strong>.getText()</strong>.toString()"</p> <p>Here is my main</p> <pre><code>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(); } }); } } </code></pre> <p>Here is the layout</p> <pre><code>&lt;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" &gt; &lt;TextView android:id="@+id/dialogueText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="please input your name:" /&gt; &lt;EditText android:id="@+id/nameBox" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/dialogueText" /&gt; &lt;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" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>I am new to programing in android, please kindly explain what went wrong.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload