Kotlin readLine()函数无法正常工作 [英] Kotlin readLine() function not working properly

查看:131
本文介绍了Kotlin readLine()函数无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在kotlin中编写了一个简单的用户输入代码,并尝试在intellij Idea上运行它,但是当我运行该代码时,输入文本"部分出现,我可以键入一些单词,但是readLine()似乎没有用,因为它没有继续到最后一个println语句.

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.

这是我的 main.kt 文件的内容

fun main(args: Array<String>) {
    print("Enter text: ")

    val stringInput = readLine()!!
    println("You entered: $stringInput")
}

这是我的 build.gradle.kts 文件的内容

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?

推荐答案

首先,感谢那些回答了这些问题的人,事实证明,解决方案只是更改Edit Configurations中的JRE选项.菜单中,最初将其设置为默认选项,然后将其更改为其他选项,然后将其还原为默认值.现在,它可以完美运行了!

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!

这篇关于Kotlin readLine()函数无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆