Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin: Unresolved reference: java

I surprised, because i was able to checkout and run a Kotlin project from Github without this error, and now get get this Java-Error

Unresolved reference: java

I using

  • kotlinc-jvm 1.3.60 (JRE 11.0.4+10-b520.11),
  • IDEA 2019.3,
  • Kernel: 5.3.15-1-MANJARO x86_64 bits: 64 compiler: gcc v: 9.2.0 Desktop: Xfce 4.14.1 Distro: Manjaro Linux

i tried hit Alt+Enter. IDE manual says: "Alt+Enter: Show intention actions and quick-fixes."

This is my File-Name:

/home/me/IdeaProjects/KeyEvent-Reader-Demo/src/Test.kt

Same Error i found here: https://discuss.kotlinlang.org/t/kotlin-unresolved-reference-java/6734

like image 481
SL5net Avatar asked May 16 '26 16:05

SL5net


2 Answers

I had the same problem, the @y.bedrov's suggestion helps me.

The issue is that the Classpath is empty (under Project Structure -> Platform Settings -> SDKs -> <choose active SDK> -> Classpath)

To fix this, you can recreate the SDK:

  1. Project Structure -> Platform SDKs -> <choose active SDK> -> "-"
  2. Project Structure -> Platform SDKs -> "+" -> <choose target SDK location>
like image 94
PavelPraulov Avatar answered May 18 '26 04:05

PavelPraulov


This was definitely some IntelliJ peoblem for me. I could solve the issue by stupidly deleting the "problematic" class and creating it again:

  • Delete class and imports that refer to it in project
  • Create the same class and adding imports

What generally people also suggest when having similar problem (but didn't help in my case):

  • Restart IDE (File -> Invalidate caches... )
  • Check Platform SDKs as mentioned in another answer here
  • IntelliJ -> PReferances -> Build, Execution, Deployment -> Make sure that Kotlin Compiler and Java Compiler match in versions.
like image 45
Diana Avatar answered May 18 '26 05:05

Diana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!