0

My code was working fine a day ago but now my application crashes with particular error when I try to use to populate html text inside my TextView i am using android JellyBean 4.4

Exception: E/UncaughtException: java.lang.NoClassDefFoundError: android/text/Html$HtmlParser

if (Build.VERSION.SDK_INT >= 24) {
            holder.desc.setText(Html.fromHtml(desc, Html.FROM_HTML_MODE_LEGACY));
            holder.title.setText(Html.fromHtml(title, Html.FROM_HTML_MODE_LEGACY));

        } else {
            //this is where i am getting exception
            holder.desc.setText(Html.fromHtml(desc));
            holder.title.setText(Html.fromHtml(title));
        }
Mehvish Ali
  • 732
  • 2
  • 10
  • 34

1 Answers1

1

you can try this create a method like below code

@SuppressWarnings("deprecation")
public static Spanned fromHtml(String data){
    Spanned result;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
       result = Html.fromHtml(data,Html.FROM_HTML_MODE_LEGACY);
    } else {
       result = Html.fromHtml(data);
    }
    return result;
}

than use this way

holder.desc.setText(fromHtml(desc));
holder.title.setText(fromHtml(title));
AskNilesh
  • 67,701
  • 16
  • 123
  • 163