Peltier Cooler
Peltier Cooler

Reputation: 169

Error using toString() with EditText

Using this line to get the text in an EditText field to get the string to translate

texttotranslate = (String) txtText.toString();

I get errors of this type:

09-15 15:20:13.311: E/ATTN:(27603): android.widget.EditText{421dbeb8 VFED..CL .F...... 0,190-720,260 #7f0b0029 app:id/txtText}- your input

where

"(27603): android.widget.EditText{421dbeb8 VFED..CL .F...... 0,190-720,260 #7f0b0029 app:id/txtText"

is the value found in texttotranslate. The actual input was supposed to be the word "yes".

Has anyone seen errors of this type? Am I using toString() incorrectly?

Upvotes: 0

Views: 65

Answers (2)

Cesar Gonzalez
Cesar Gonzalez

Reputation: 11

In java you need to use the getter method getText() to get the text property, like this:

(String)txtText.getText().toString();

Upvotes: 1

codeMagic
codeMagic

Reputation: 44571

Use the getText() method

Return the text the TextView is displaying.

texttotranslate = txtText.getText().toString();

Upvotes: 3

Related Questions