Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

android

This will be displayed in a mono-spaced font. The first four spaces will be stripped off, but all other white space will be preserved.

String letterStr = null;
letterStr = (String)((TextView)view).getText();
like image 424
Yan Abner Avatar asked Mar 15 '23 08:03

Yan Abner


1 Answers

the String contains html markups, and android treats it as a Spannable.

You can either assign the return value of getText() to a CharSequence object, which super class for both String and Spannable, or replace the cast with toString()

letterStr = ((TextView)view).getText().toString();

the former will preserve the html markups, the latter will not

like image 132
Blackbelt Avatar answered Apr 24 '23 21:04

Blackbelt