Answered step by step
Verified Expert Solution
Question
1 Approved Answer
When the app launches , the app keeps crashing. Find the errors in the code below to fix the crashing issue. kt code: package com.example.thediceroller
When the app launches the app keeps crashing. Find the errors in the code below to fix the crashing issue.
kt code:
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?
super.onCreatesavedInstanceState
setContentViewRlayout.activitymain
ivDice findViewByIdRidivDice
ivDice findViewByIdRidivDice
tvSum findViewByIdRidtvSum
btnRoll findViewByIdRidbtnRoll
btnRoll.setOnClickListener
rollDice
@SuppressLintSetTextIn
private fun rollDice
val dice Random.nextInt
val dice Random.nextInt
val sum dice dice
ivDicesetImageResourcegetDiceDrawabledice
ivDicesetImageResourcegetDiceDrawabledice
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
xml code:
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