I was trying to make a Dice Roller app on Android Studio but when i put this Random() i get an error by saying that "Cannot create an instance of an abstract class" Please Help me
package com.example.diceroller
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val rollbutton: Button = findViewById(R.id.roll_button)
rollbutton.setOnClickListener(
View.OnClickListener { diceRoll() }
)
}
private fun diceRoll() {
val resultText: TextView = findViewById(R.id.result_text)
val randomInt = Random().nextInt(6) + 1
resultText.text = randomInt.toString()
}
}
I Expect the output to be random between 6 to 1 whenever i click button
Aucun commentaire:
Enregistrer un commentaire