2017-09-13 6 views
0

Mon code fonctionnait très bien il y a un jour, mais maintenant mes accidents d'application avec erreur particulière lorsque je tente d'utiliser pour remplir le texte html dans mon TextView je suis en utilisant Android JellyBean 4,4NoClassDefFoundError Html.fromHtml android

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)); 
     } 

Répondre

1

vous pouvez essayer cette créer une méthode comme ci-dessous le 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; 
} 

que d'utiliser cette façon

holder.desc.setText(fromHtml(desc)); 
holder.title.setText(fromHtml(title));