You are currently viewing Adding a second dice roller

Adding a second dice roller

The following is an excerpt of code from a Dice Roller application I am creating from the Google Grow Certificates program. It operates as intended with the first line of code for the 6 sided die, but when I attempted to simply duplicate the function and express a second dice roll, the findViewById keeps turning up an Unresolved Reference. What am I doing wrong/how can I resolve this unresolved reference?

private fun rollDice() {// Create new Dice object with 6 sides and roll itval dice = Dice(6)val diceRoll = dice.roll()

//Update the screen with the dice rollval resultTextView: TextView = findViewById(R.id.textView)resultTextView.text = diceRoll.toString()}}

*/*** Roll a second die and update screen with the result using the same button*/*private fun rollDice2() {val dice2 = Dice(20)val diceRoll2 = dice2.roll()

val resultTextView2: TextView = findViewById(R.id.textView2)resultTextView2.text = diceRoll2.toString()}

Edit: I created a second textView (named textView2) in the parent constraint layout. I currently have it constrained within the layout, and the order is currently textView, button, textView2

Edit2: Activity_main.xml screenshot

https://preview.redd.it/fj8okl4i28581.png?width=1188&format=png&auto=webp&s=b1f77e1baed813d466ff97c9e51424d63704e1a7

submitted by /u/Jubblibursde
[link] [comments]