Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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.osBundle
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 ivDice: ImageView
private lateinit var ivDice: ImageView
private lateinit var tvSum: TextView
private lateinit var btnRoll: Button
override fun onCreatesavedInstanceState: Bundle?
this.onCreatesavedInstanceState
setContentViewRlayout.activitymain
ivDice findViewByIdRidivDice
ivDice findViewByIdRidivDice
tvSum findViewByIdRidtvSum
btnRoll findViewByIdRidbtnRoll
btnRoll.setOnClickListener
rollDice
private fun setContentViewactivityMain: Any
TODONot yet implemented"
@SuppressLintSetTextIn
private fun rollDice
val dice Random.nextInt
val dice Random.nextInt
val sum dice dice
ivDicesetImageResourcegetDiceDrawabledice
ivDicesetImageResourcegetDiceDrawabledice
this.tvSum.text "Sum: $sum"
private fun getDiceDrawablediceValue: Int: Int
return when diceValue
Rdrawable.dice
Rdrawable.dice
Rdrawable.dice
Rdrawable.dice
Rdrawable.dice
else Rdrawable.dice
private fun Any.onCreatesavedInstanceState: Bundle?
The xml code is as follows:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started