Kotlin: Unresolved reference: java


#1

Just getting started with Kotlin (1.2.21 plugin) in IntelliJ IDEA (2017.3.4) using version 9.0.4 of the JDK. I’m using the IDEA build tools. Wrote a simple class as follows that starts with the following line:

   import java.time.LocalDateTime

The compiler says “Error:(1, 8) Kotlin: Unresolved reference: java”. Is this a Kotlin thing or am I missing something in the IDEA configuration?


#2

This code works in the same environment as yours

import java.time.LocalDateTime

fun main(args: Array<String>) {
    val date = LocalDateTime.now()
    println(date)
}

Can you give more information about the error, or maybe show more code?


#3

Make sure your Project SDK in IntelliJ is set up correctly.


#4

SackCatellon,

Your code doesn’t compile in my environment (same error). See the compiler messages below. (I don’t know the reason for the Javascript warnings.)

Information:Kotlin: kotlinc-js 1.2.21 (JRE 9.0.4+11)
Information:2/22/2018 12:14 PM - Compilation completed with 2 errors and 7 warnings in 2s 610ms
Warning:Kotlin: ‘C:/Users/Servant/.IdeaIC2017.3/config/plugins/Kotlin/kotlinc/lib/kotlin-stdlib.jar’ is not a valid Kotlin Javascript library
Warning:Kotlin: ‘C:/Users/Servant/.IdeaIC2017.3/config/plugins/Kotlin/kotlinc/lib/kotlin-reflect.jar’ is not a valid Kotlin Javascript library
Warning:Kotlin: ‘C:/Users/Servant/.IdeaIC2017.3/config/plugins/Kotlin/kotlinc/lib/kotlin-test.jar’ is not a valid Kotlin Javascript library
Warning:Kotlin: ‘C:/Users/Servant/.IdeaIC2017.3/config/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-jre7.jar’ is not a valid Kotlin Javascript library
Warning:Kotlin: ‘C:/Users/Servant/.IdeaIC2017.3/config/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-jre8.jar’ is not a valid Kotlin Javascript library
Warning:Kotlin: ‘C:/Users/Servant/.IdeaIC2017.3/config/plugins/Kotlin/kotlinc/lib’ is not a valid Kotlin Javascript library
Warning:Kotlin: ‘C:/Users/Servant/.IdeaIC2017.3/config/plugins/Kotlin/lib’ is not a valid Kotlin Javascript library
C:\Users\Servant\Documents\Projects\Sample\Code\src\Sample.kt
Error:(1, 8) Kotlin: Unresolved reference: java
Error:(4, 16) Kotlin: Unresolved reference: LocalDateTime

Nanodeath,

I’ve examined the project settings at length, but I may lack the experience with Kotlin and IDEA to know what to look for. The plugin for Kotlin is installed, and the Kotlin compiler is configured to use the correct version of the plugin.


#5

Looks like you are using Kotlin2Js. If you are using idea to compile the code, make sure your project settings are set to Kotlin(JVM) and not Kotlin Java Script.


#6

Wasabi375,

I don’t see anywhere in the project settings to do that explicitly. I created a new project and selected KotlinJVM in the setup wizard and the code compiles fine now.

Thanks,

Servant