android studio,科特林
我尝试将字符串转换为int后,app不断停止。我需要整数来获取随机数。
kotlin的新手,所以有什么帮助吗?
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val goButton = findViewById<Button>(R.id.goButton)
val textViewResult = findViewById<TextView>(R.id.textViewResult)
val editText = findViewById<EditText>(R.id.editTexts)
val txt = editText.text.toString().toInt()
goButton.setOnClickListener {
val rand = java.util.Random().nextInt(txt)
textViewResult.text=rand.toString()
}
}