# Kotlin: Unresolved reference: java

**URL:** <https://discuss.kotlinlang.org/t/kotlin-unresolved-reference-java/6734>\
**Category:** Uncategorized\
**Created:** [February 22, 2018, 5:07am UTC](https://discuss.kotlinlang.org/t/kotlin-unresolved-reference-java/6734 "2018-02-22T05:07:04Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![servant](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@servant](https://discuss.kotlinlang.org/u/servant)\
**Post date:** [February 22, 2018, 5:07am UTC](https://discuss.kotlinlang.org/t/kotlin-unresolved-reference-java/6734/1 "2018-02-22T05:07:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![SackCastellon](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/sackcastellon/32/4553_2.png) [@SackCastellon](https://discuss.kotlinlang.org/u/SackCastellon)\
**Post date:** [February 22, 2018, 9:59am UTC](https://discuss.kotlinlang.org/t/kotlin-unresolved-reference-java/6734/2 "2018-02-22T09:59:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![nanodeath](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/nanodeath/32/1803_2.png) [@nanodeath](https://discuss.kotlinlang.org/u/nanodeath)\
**Post date:** [February 22, 2018, 5:20pm UTC](https://discuss.kotlinlang.org/t/kotlin-unresolved-reference-java/6734/3 "2018-02-22T17:20:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![servant](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@servant](https://discuss.kotlinlang.org/u/servant)\
**Post date:** [February 22, 2018, 8:27pm UTC](https://discuss.kotlinlang.org/t/kotlin-unresolved-reference-java/6734/4 "2018-02-22T20:27:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Wasabi375](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wasabi375/32/4741_2.png) [@Wasabi375](https://discuss.kotlinlang.org/u/Wasabi375)\
**Post date:** [February 22, 2018, 8:45pm UTC](https://discuss.kotlinlang.org/t/kotlin-unresolved-reference-java/6734/5 "2018-02-22T20:45:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![servant](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@servant](https://discuss.kotlinlang.org/u/servant)\
**Post date:** [February 22, 2018, 9:37pm UTC](https://discuss.kotlinlang.org/t/kotlin-unresolved-reference-java/6734/6 "2018-02-22T21:37:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![salmalearns2020](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@salmalearns2020](https://discuss.kotlinlang.org/u/salmalearns2020)\
**Post date:** [November 28, 2020, 2:03pm UTC](https://discuss.kotlinlang.org/t/kotlin-unresolved-reference-java/6734/7 "2020-11-28T14:03:32Z")

</div>

Hello, is there a reason why java can’t be imported in a kotlin file is a Kotlin/Js project? I am trying to build a simple frontend to my already written kotlin files in which I use java libraries but I get this unresolved reference error, not sure what the problem is

---

<div class="post-metadata">

**Author:** ![rjaros](https://avatars.discourse-cdn.com/v4/letter/r/9f8e36/32.png) [@rjaros](https://discuss.kotlinlang.org/u/rjaros)\
**Post date:** [November 28, 2020, 2:29pm UTC](https://discuss.kotlinlang.org/t/kotlin-unresolved-reference-java/6734/8 "2020-11-28T14:29:38Z")

</div>

Kotlin/JS and Kotlin/JVM are completely different targets. Java libraries can only by used in JVM projects.

---

<div class="post-metadata">

**Author:** ![salmalearns2020](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@salmalearns2020](https://discuss.kotlinlang.org/u/salmalearns2020)\
**Post date:** [November 28, 2020, 2:44pm UTC](https://discuss.kotlinlang.org/t/kotlin-unresolved-reference-java/6734/9 "2020-11-28T14:44:18Z")

</div>

Do you recommend anything in order to implement a frontend? I found that kotlin/JS is the simplest way since my project is really not that complicated. I don’t want to use something like kolin/React. I have found very little resources about frontend with kotlin unfortunately.

---

<div class="post-metadata">

**Author:** ![rjaros](https://avatars.discourse-cdn.com/v4/letter/r/9f8e36/32.png) [@rjaros](https://discuss.kotlinlang.org/u/rjaros)\
**Post date:** [November 28, 2020, 3:54pm UTC](https://discuss.kotlinlang.org/t/kotlin-unresolved-reference-java/6734/10 "2020-11-28T15:54:17Z")

</div>

You can try [https://kvision.io](https://kvision.io) (disclaimer: I’m the author of this framework)

---

<div class="post-metadata">

**Author:** ![salmalearns2020](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@salmalearns2020](https://discuss.kotlinlang.org/u/salmalearns2020)\
**Post date:** [November 29, 2020, 2:54pm UTC](https://discuss.kotlinlang.org/t/kotlin-unresolved-reference-java/6734/11 "2020-11-29T14:54:03Z")

</div>

Thank you! Will using Kvision still require me to not import java in my kotlin files though?

---

<div class="post-metadata">

**Author:** ![rjaros](https://avatars.discourse-cdn.com/v4/letter/r/9f8e36/32.png) [@rjaros](https://discuss.kotlinlang.org/u/rjaros)\
**Post date:** [November 29, 2020, 3:16pm UTC](https://discuss.kotlinlang.org/t/kotlin-unresolved-reference-java/6734/12 "2020-11-29T15:16:28Z")

</div>

Yes, it does.  
If you absolutely need to use JVM code (e.g. your business logic is already implemented as a JVM library), you have two options if you want to stay with Kotlin.  
First - build fullstack application with Kotlin Multiplatform and split your code between the frontend (Kotlin/JS) and the backend (Kotlin/JVM). KVision has great support for building fullstack apps.  
Second - use a JVM only framework (e.g. Ktor, Jooby, Javalin, Spring Boot, Vaadin, Kweb) and create typical server side application.

---

<div class="post-metadata">

**Author:** ![salmalearns2020](https://avatars.discourse-cdn.com/v4/letter/s/3d9bf3/32.png) [@salmalearns2020](https://discuss.kotlinlang.org/u/salmalearns2020)\
**Post date:** [November 29, 2020, 3:50pm UTC](https://discuss.kotlinlang.org/t/kotlin-unresolved-reference-java/6734/13 "2020-11-29T15:50:09Z")

</div>

Sounds great I think I will stick with the multiplatform idea then. Thanks again!
