我如何通过kotlin将HTML代码解码到Android?

我如何通过kotlin将HTML代码解码到Android?,android,casting,kotlin,Android,Casting,Kotlin,我正在尝试解码HTML实体,目前我的代码是: val str = name val textView = findViewById<View>(R.id.text) as TextView textView.text = Html.fromHtml(str, Html.FROM_HTML_MODE_COMPACT) 您的错误与HTML处理无关,这一行出现异常,因为findViewById返回null,然后对TextView的转换失败: val textView = findView

我正在尝试解码HTML实体,目前我的代码是:

val str = name
val textView = findViewById<View>(R.id.text) as TextView
textView.text = Html.fromHtml(str, Html.FROM_HTML_MODE_COMPACT)

您的错误与HTML处理无关,这一行出现异常,因为
findViewById
返回
null
,然后对
TextView
的转换失败:

val textView = findViewById<View>(R.id.text) as TextView
val textView = findViewById<View>(R.id.text) as TextView
val textView = findViewById<TextView>(R.id.text)
val textView: TextView = findViewById(R.id.text)