11
fun main() {
    fun convert(x: Double, converter: (Double) -> Double) : Double{
        val result = converter(x)
        println("$x is converted to $result")
        return result
    }
    fun convertFive(converter: (Int) -> Double) : Double {
        val result = converter(5)
        println("5 is converted to $result")
        return result
    }

    convert(20.0) { it * 1.8 + 32}
    convertFive { it * 1.8 + 32 }
}

// i got this error when i updated my intelliJ Idea and ran this //

Kotlin: [Internal Error] java.lang.ExceptionInInitializerError

4
  • Can you kindly post the rest of the error? It may be that you need to update your Java, Kotlin, or gradle versions Commented Mar 26, 2021 at 10:20
  • That's all i see and nothing more Commented Mar 26, 2021 at 10:56
  • There is no problem with the code in the question.  (It compiles and runs fine in my IntelliJ.)  It must be a problem with your set-up. Commented Mar 26, 2021 at 11:06
  • This is the new error it's showing "Kotlin: [Internal Error] java.lang.NOClassDefFoundError: Could not initialize class com.intellij,pom.java.LanguageLevel" Commented Mar 26, 2021 at 12:12

2 Answers 2

25

The problem is that the current version of the Kotlin compiler (1.4.31, 1.5-M1) doesn't work on JDK 16. Please use JDK < 16 for now. Related issue: https://youtrack.jetbrains.com/issue/KT-45566.

Sign up to request clarification or add additional context in comments.

2 Comments

It didn't work for me I tried many versions !!
I think Kotlin 1.5.10 works with JDK 16 now, try updating Kotlin
6

Try File > Invalidate Caches/Restart...

1 Comment

Even if you do the steps in described in the accepted answer, this was a necessary step. In my case as the issue persisted up to the point I did what was suggested here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.