0

I'm following the intelliJ IDEA tutorial titled Create your first Kotlin application (Last modified: 08 March 2021). Here are the various versions I'm using:

~$ java -version
java version "16" 2021-03-16
Java(TM) SE Runtime Environment (build 16+36-2231)
Java HotSpot(TM) 64-Bit Server VM (build 16+36-2231, mixed mode, sharing)

~$ javac -version
javac 16

jdk version

intelliJ version

kotlin version

Here's my code:

fun main(args: Array<String>) {
    println("What is your name?")
    val name = readLine()
    println("Hello $name")
}

Here's what my project structure looks like:

enter image description here

I notice that it says "Kotlin not configured" above my code, but when I go to Tools > Kotlin > Configure Kotlin in Project, I get

kotlin config:

In the Event Log pane, I see this:

4/15/21
1:54 PM Download pre-built shared indexes
                Reduce the indexing time and CPU load with pre-built JDK shared indexes
                Always download
                Download once
                Don't show again
                Configure...

1:54 PM Gradle sync started

1:54 PM Gradle sync failed: Unsupported class file major version 60 (5 s 329 ms)

1:55 PM No IDE or plugin updates available

In the Problems(?) pane, I see this:

Unresolved reference: println
Unresolved reference: readLine
Unresolved reference: println
Parameter 'args' is never used
Package directive doesn't match file location

Any ideas on why the basic functions in my program are not recognized?

Thanks for looking!

Edit: I tried downloading JDK 15 and specifying that in my Project Structure, but I got the same results:

jdk version

enter image description here

7stud
  • 46,922
  • 14
  • 101
  • 127
  • Try looking into this question. [Kotlin unresolved reference in IntelliJ](https://stackoverflow.com/questions/31712046/kotlin-unresolved-reference-in-intellij) – Umar zzstu Syed Apr 15 '21 at 20:53
  • @UmarzzstuSyed, I looked at the answers there before posting my question. I tried some things, didn't understand other things. – 7stud Apr 15 '21 at 20:59
  • Check your Kotlin compiler version from `Build, Execution, Deployment -> Compiler -> Kotlin Compiler`. After that check Kotlin version from `build.gradle.kts` file. – shn Apr 15 '21 at 21:05
  • @Furkan, I can't find `Build, Execution, Deployment` anywhere. – 7stud Apr 15 '21 at 22:48
  • @Furkan, Okay, I found it under `intelliJ IDEA > Preferences`. For the Kotlin compiler: `Language version: Latest stable(1.4)`, `API version: Latest stable(1.4)`. I installed everything yesterday, so all software should be the latest version. – 7stud Apr 15 '21 at 22:56

2 Answers2

0

try build>clean project. As for your unresolved references, you can double-click/left-click > show context options. If that doesn't work then maybe reinstall InteliJ Idea or download Android Studio which has a lot more support on google and yt.

0

Okay, I got it working. I'll try to figure out what I did.

tldr; I had to switch from JDK 16 to JDK 15 to get my hello world console application to run.

First, when I was setting up the project, I chose the wrong Project Template: I selected JVM - Application rather than JVM - Console Application. This is what I needed to do:

enter image description here

So, I started a new project, chose the right template, and I typed in my code, and I noticed a Build pane at the bottom left displayed:

enter image description here

I tried Build > Build Project, and nothing changed. So, I tried the Run menu item: the first section of the Run menu was grayed out, but there was another Run command in the second section of the Run menu. I selected that Run, and a little window popped up with the following:

      Run
  0  Edit Configurations

The "0 Edit Configurations" line was highlighted, and I got nowhere trying to figure out how to Run my code.

So, I started yet another new project, and this time I selected a different JDK, version 15:

enter image description here

After clicking Next, then Finish, I typed in my code, and this time the Build pane looked like the following (without me doing anything but typing in my code):

enter image description here

After I finished typing in my code, as the tutorial described, this time there was a little green arrow in the gutter:

enter image description here

When I clicked on the green arrow in the gutter, I could successfully Run my program.

So, it appears that you cannot use JDK 16, and you have to use JDK 15. intelliJ was able to detect all my installed Java versions, so any version you have installed should appear as a choice in the the project settings. You may have to quit intelliJ, then restart intelliJ after you install JDK 15 in order to see it listed as a choice under Project JDK: when you create a project.

7stud
  • 46,922
  • 14
  • 101
  • 127