编译任何Java代码后,当我尝试从cmd运行它时,都会得到以下信息:
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)
我有:
jdk-11.0.1
jre1.8.0_192
我的jdk/bin
环境中也有PATH
是可生存的。当我使用IDE并且PC可以识别java/c -version
命令时,代码可以正常运行。
答案 0 :(得分:4)
class file version 55.0
表示此.class文件is compiled with JDK 11。该文件可以在Java 11或更高版本上运行,但是您的java
使用的是jre1.8.0_192
。
您应该更改JAVA_PATH
或PATH
环境变量,以使命令java
指向Java java
的11版本,例如,位于您{ {1}},或在jdk-11.0.1
中使用该java.exe
运行此.class文件。