Kotlin readLine() function not working properly

隐身守侯 提交于 2021-01-29 06:37:37

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!