Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I resolve this error please "Kotlin: [Internal Error] java.lang.ExceptionInInitializerError"

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

like image 799
Hyelngtil Isaac Avatar asked Mar 26 '21 09:03

Hyelngtil Isaac


People also ask

How do I fix Java Lang ExceptionInInitializerError?

We can resolve the java. lang. ExceptionInInitializerError by ensuring that static initializer block of classes does not throw any Runtime Exception. We can resolve also resolve this exception by ensuring that the initializing static variable of classes also doesn't throw any Runtime Exception.

What does Java Lang ExceptionInInitializerError mean?

The ExceptionInInitializerError indicates that an unexpected exception has occurred in a static initializer. Basically, when we see this exception, we should know that Java failed to evaluate a static initializer block or to instantiate a static variable.

Why do we get Java Lang ExceptionInInitializerError?

Class ExceptionInInitializerError. Signals that an unexpected exception has occurred in a static initializer. An ExceptionInInitializerError is thrown to indicate that an exception occurred during evaluation of a static initializer or the initializer for a static variable.

Why is my Kotlin compiler not working on JDK 16?

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. Try File > Invalidate Caches/Restart... Thanks for contributing an answer to Stack Overflow!

What is exceptionininitializererror in Java?

- GeeksforGeeks How to Resolve Java.lang.ExceptionInInitializerError In Java? An unexpected, unwanted event that disturbed the normal flow of a program is called an Exception. 1. Checked Exception

How to fix Kotlin REPL is not working?

To update the Kotlin plugin go to Settings -> Languages & Frameworks -> Kotlin. Click the check again button to know if you have any new update. If so, then update it and restart, then see if Kotlin REPL is working or not. Show activity on this post. I fixed it by using JDK 15 instead of 16. File -> New -> Project...

How to update the Kotlin plugin in IntelliJ IDEA Community Edition 2021?

I installed IntelliJ IDEA Community Edition 2021.1.3 today and am using JDK-16.0.1 on my linux PC. This also happened in my case. I went through all the settings at first then I found that I had a Kotlin update. After my update the Kotlin REPL started without any error. To update the Kotlin plugin go to Settings -> Languages & Frameworks -> Kotlin.


2 Answers

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.

like image 87
Alexey Belkov Avatar answered Oct 20 '22 08:10

Alexey Belkov


Try File > Invalidate Caches/Restart...

like image 29
duyvu1311 Avatar answered Oct 20 '22 08:10

duyvu1311