2

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?

Raka
  • 31
  • 7
  • Works fine for me in IntelliJ without gradle, so must be related to gradle. – Adam Millerchip Nov 25 '20 at 07:53
  • There is no problem (as I see it) it the two files you supplied. What exactly is the problem you face? You start the application and "Enter text:" shows up. Then you add some text and press enter. What happens now? – vitfo Nov 25 '20 at 09:21
  • it still runs, but it doesn't continue to the "You entered part" – Raka Nov 25 '20 at 09:31
  • 1
    I've found the solution to this, thank you so much for your help, I appreciate it! – Raka Nov 25 '20 at 09:40

1 Answers1

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!

Raka
  • 31
  • 7
  • Hey, can you tell me what you mean by "change the JRE options in the Edit Configurations menu"? Is the Edit Configurations menu specific to Intellij IDEA, or something else? I am having this exact problem right now. I even used the same code from a tutorial on the `readLine` function before I knew this was posted. – user18798042 Oct 25 '22 at 02:26
  • yes it is specific to Intellij IDEA – Raka Dec 05 '22 at 10:48