0
votes

I am beginner in Kotlin. I am getting the following exception while doing following:

kotlinc sample.kt -include-runtime -d sample.jar

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/jetbrains/kotlin/preloading/Preloader : Unsupported major.minor version 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) at java.net.URLClassLoader.access$100(URLClassLoader.java:71) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

Code

fun main(args: Array<String>){
      var a : Int
      a = getLength("Hello")
      println("length of word is $a")
  }

  fun getLength(word : Any) : Int? {
      if (word !is String) return null
      return word.length
  }

And kotlin version is Kotlin version 1.2.21-release-88 (JRE 1.7.0_79-b15)

2
What is your JDK version? Please add output of java -version command. - asm0dey
Got it. Now I have updated the jdk. java -version java version "1.8.0_92" Java(TM) SE Runtime Environment (build 1.8.0_92-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode) Works fine. Thanks @asm0dey - esu
Added answer, hope it helps. - asm0dey

2 Answers

1
votes

JDK version which was used to build sample.jar is built with java version newr than one which you're using to compile kotlin file. You have 2 ways:

  1. Rebuild sample jar with your current version of JDK
  2. Update JDK on your computer and try compiling again
0
votes

Install an updated of JDK, Go to File> Project Structure. Sele and select the newer JDK version. Then you'll be ready to go,

cheers