Danny Piper Danny Piper - 1 year ago 503
Java Question

Android Studio getText() and setText() not working with error: "can't resolve method "getText/setText"()"

So my app needs to read text from a text box with a tag of "inText" do stuff to it (that stuff works) then write the output to a box with the id of "outView". I've been doing this with setText() and getText().

setText() was for writing the output below is what I used:


getText() was for reading the input text then writing it to a variable and below is what I used:

String mEdit = (EditText)findViewById(R.id.inText.getText()).toString();

Answer Source

You set the getText() and setText() method in wrong place. getText() and setText() are methods of TextView and EditText classes. But here you used it as a method of id. That's why it's showing "Can't resolve method getText/setText()". As id has no such methods.

You can do the following.

((TextView) findViewById(R.id.outView)).setText(textoutput);


String mEdit = ((EditText) findViewById(R.id.inText)).getText().toString();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download