'Unresolved reference: readln - in InteliJ IDEA

this code in a new project throws "Unresolved reference: readln" error

fun main() {
    val z = readln()
}

But on another project in Intelij IDEA works ok. Why so?

enter image description hereenter image description here



Solution 1:[1]

readln() was added in Kotlin 1.6. Make sure you are using Kotlin 1.6 or later.

Solution 2:[2]

The readln function is only available since version 1.6.0 of Kotlin, see it's documentation

Most likely the other project uses an older version of Kotlin, in which this function was not available yet.

Solution 3:[3]

thanks!

I had to go to Preferences -> Languages & Frameworks -> Kotlin - and change Update channel from "Stable" to Early Access Preview 1.6.x or 1.7.x

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tenfour04
Solution 2 Endzeit
Solution 3 ??????? ????????