I have followed this tutorial for building an android app. https://www.youtube.com/watch?v=EOfCEhWq8sg
It goes well up until the end, where we generate a random val using Random.nextInt(). In Android Studio (3.3), I get an error :
an unresolved reference to nextInt.
I have made sure I am using the right spelling. This program uses Kotlin, and I even imported java.util.* to get the Random library imported.
Please help me out, it is very discouraging not being able to get such a simple application built.
Thanks.
If you use Random class from java.util package you need to create an instance of Random class. Instances in Kotlin are created using NameOfClass() syntax:
java.util.Random().nextInt()
If you use Random class from kotlin.random package you don't need to create an instance of the class:
kotlin.random.Random.nextInt()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With