user3207230
user3207230

Reputation: 597

LocalDateTime in IntelliJ IDEA Kotlin shows as unresolved reference

java.time seems to be missing entirely. The code I'm trying it in is a simple

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

Seems like I am missing something fundamental, but all I have been doing is following along in a tutorial and it just worked for the tutor.

Upvotes: 3

Views: 3136

Answers (1)

hotkey
hotkey

Reputation: 148089

The LocalDateTime class has only been introduced in Java SE 8, so you need to compile your project against JDK 8 or newer.

Make sure that:

  • You have an installed JDK 8 or newer;

  • Your project is compiled against this JDK 8+.

    (In IntelliJ IDEA, Ctrl/+Shift+Alt+SProjectProject SDK; other build systems should be set up separately)

With the JDK configured correctly, the code should run fine as-is: (demo)

Upvotes: 4

Related Questions