القرآن الكريم القرآن الكريم - 3 months ago 10
Java Question

Can't cast from Edit Text to String

EditText entername = (EditText)findViewById(R.id.enter_name);

// this line convert it to String

String q =entername.getText().toString();


//why it is not working in this way ???

String d = (String) entername.getText();

Answer

The method getText() doesn't return a String, but an Editable.

Note that an Editable doesn't extends String, but it implements CharSequence, so it can be used in many methods that accept CharSequence.

Comments