Question: find and correct the errors in the dice roller kt code below. The code was written but when the app is launched an error app

find and correct the errors in the dice roller kt code below. The code was written but when the app is launched an error "app has stopped " keep popping up... the code is as follows:
package com.example.thediceroller
import android.annotation.SuppressLint
import android.os.Bundle
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import kotlin.random.Random
class MainActivity : AppCompatActivity(){
private lateinit var ivDice1: ImageView
private lateinit var ivDice2: ImageView
private lateinit var tvSum: TextView
private lateinit var btnRoll: Button
override fun onCreate(savedInstanceState: Bundle?){
this.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
ivDice1= findViewById(R.id.ivDice1)
ivDice2= findViewById(R.id.ivDice2)
tvSum = findViewById(R.id.tvSum)
btnRoll = findViewById(R.id.btnRoll)
btnRoll.setOnClickListener {
rollDice()
}
}
private fun setContentView(activityMain: Any){
TODO("Not yet implemented")
}
@SuppressLint("SetTextI18n")
private fun rollDice(){
val dice1= Random.nextInt(1,7)
val dice2= Random.nextInt(1,7)
val sum = dice1+ dice2
ivDice1.setImageResource(getDiceDrawable(dice1))
ivDice2.setImageResource(getDiceDrawable(dice2))
this.tvSum.text = "Sum: $sum"
}
private fun getDiceDrawable(diceValue: Int): Int {
return when (diceValue){
1-> R.drawable.dice1
2-> R.drawable.dice2
3-> R.drawable.dice3
4-> R.drawable.dice4
5-> R.drawable.dice5
else -> R.drawable.dice6
}
}
}
private fun Any.onCreate(savedInstanceState: Bundle?){
}
The xml code is as follows:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!