jeudi 23 mai 2019

Cannot create an instance of an abstract class (Random)

I am trying to learn Kotlin so I was following a tutorial on internet where instructor wrote a code which worked fine in with them but it gives error to me.

This is the error

Error:(26, 17) Kotlin: Cannot create an instance of an abstract class

import kotlin.random.Random

fun main(args: Array<String>) {
    feedTheFish()
}

fun feedTheFish() {
    val day = randomDay()
    val food = "pellets"
    print("Today is ${day} and the fish eat ${food}")
}


fun randomDay():String {
    val week = listOf ("Monday", "Tuesday", "wednesday", "thursday", "friday", "saturday", "sunday")
    return week[ Random().nextInt(7)]
}

I am getting error from return statement, I think from Random. Please help me to understand this and fix this code.




Aucun commentaire:

Enregistrer un commentaire