2

After compiling any Java code, when I try run it from cmd I get this:

  Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: HelloWorld has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

I have:

jdk-11.0.1
jre1.8.0_192

I also have jdk/bin in my PATH enviroment virable. Code runs fine when I use IDE and my PC recognizes java/c -version command.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Tezro
  • 31
  • 1
  • 4
  • If you have both jdk 11 and jre 8 installed, the command-line may be using the jr 8 jvm, which won't be able to run code compiled for jdk 11 ... Have your cmd print the result of "java -version" ? – moilejter Nov 27 '18 at 17:37
  • yea when i hit java -version i get "java version "1.8.0_192". what wrong with jdk 11+ jre 8? what should i replace? – Tezro Nov 27 '18 at 17:46

1 Answers1

3

class file version 55.0 means this .class file is compiled with JDK 11. This file is allowed to run on Java 11 or above, but your java is using that jre1.8.0_192.

You should change your JAVA_PATH or PATH environment variable to make the command java points to a Java 11 version of java, for example that one located in your jdk-11.0.1, or use that java.exe inside your jdk-11.0.1 to run this .class file.

Geno Chen
  • 4,916
  • 6
  • 21
  • 39