Why show java.lang.ClassCastException: android.text.SpannableString cannot be cast to java.lang.String?

From CharSequence.toString()

Returns a string with the same characters in the same order as in this sequence.

You need to use next code.

String pasteData = item.getText().toString();

You can not cast to android.text.SpannableString because item.getText() returns CharSequence, there are a lot of implementations of it


SpannableString is not String directly. so, you can not cast. but, it can be converted to string. you can convert something to string with concatenating with empty string.

pasteData = "" + item.getText();