问题
I recently made a simple user input code in kotlin and I tried to run it on intellij Idea, but it didn't work properly, when I ran the code, the "Enter text" part showed up and I can type some words, but the readLine() didn't seem to work as it doesn't continue to the last println statement.
this is the contents of my main.kt file
fun main(args: Array<String>) {
print("Enter text: ")
val stringInput = readLine()!!
println("You entered: $stringInput")
}
here is the contents of my build.gradle.kts file
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.4.20"
application
}
group = "me.rakandhiya"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
testImplementation(kotlin("test-junit"))
}
tasks.test {
useJUnit()
}
tasks.withType<KotlinCompile>() {
kotlinOptions.jvmTarget = "1.8"
}
application {
mainClassName = "MainKt"
}
is there anything wrong in those 2 files?
回答1:
First of all, thanks to the guys that responds to the questions, it turns out that the solution to this was just changing the JRE options in the Edit Configurations
menu, it was initially set to default option, then I change it to something else, and then I revert it back to default. And now it works perfectly!
来源:https://stackoverflow.com/questions/65000410/kotlin-readline-function-not-working-properly