4

I'm just getting started with Kotlin, so I apologize if it's a dumb problem (which I think it probably is).

I'm following this guide, but ran in an issue: the readLine function ignores my first input, and returns only the second line I insert.

fun main() {
    println("What's your name?")
    val name= readLine()
    println("Hello $name!")
}

And this is the output I'm getting (">" marks my input into the console):

What's your name?
> Paul
> John
Hello John!

I'm using IntelliJ IDEA Community 2020.2, if that makes a difference. Thanks in advance for any help!

  • I've tried your code — also using IDEA Community 2020.2 — and it works as expected, reading the first line I type.  So it's not a problem with the code, nor an inherent issue with IDEA.  I can only suggest the usual things: rebuild the project, update your JRE and Kotlin plugin, Invalidate Caches and Restart, check your Maven/Gradle set-up… – gidds Dec 02 '20 at 09:37
  • Well it's happening to me on IDEA Community 2020.3 – Ger Dec 10 '20 at 15:18
  • Interestingly, when I decompiled its bytecode into Java and then ran that code, it worked as expected, without the glitch in the IDEA console. – Ger Dec 10 '20 at 15:36
  • Confirming the same behaviour on IDEA Community 2020.3. Folks, just update IDEA to 2020.3.3 - its console works correctly with `readLine()`. – Andrei K. Mar 26 '21 at 06:07
  • UPD: Sorry for misinformation, it worked correctly only once on IDEA 2020.3.3 too. – Andrei K. Mar 26 '21 at 07:52

0 Answers0