我很难让这款应用运行起来。我似乎无法找到相关的情况作为某种指导。显然单词不被识别为字符串资源,然后我的 Scrape 方法是"未解析的参考"?
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val texx: TextView=findViewById(R.id.text1) as TextView
val button:Button=findViewById(R.id.button1) as Button
button.setOnClickListener(object : View.OnClickListener{
override fun onClick(v: View) {
Scrape().execute() //should work tho
}
})
class Scrape() :AsyncTask<Void, Void, Void>() {
lateinit var words: String
override fun doInBackground(vararg params: Void?): Void? {
try {
val html = Jsoup.connect("https://www.wikipedia.com/en/Canada").get()
words = html.text()
}
catch (e: Exception) {
e.printStackTrace()
}
return null
}
override fun onPostExecute(result: Void?) {
super.onPostExecute(result)
texx.text = getString(R.string.words)
}
}
答案 0 :(得分:0)
R.string.words将引用strings.xml文件中的值。尝试将值'words'发送到asynctask
的result参数中