java运行出现JNI错误,JDK8和JDK11都安装了
1. 问题描述
因为编程的需要,所以我安装了JDK8和JDK11,在安装好了之后配置好了环境变量,之后打开Eclipse的时候,却发现一个HelloWorld都没有办法运行了,出现如下的报错:
Exception in thread "main" java.lang.UnsupportedClassVersionError: king/HelloWorld has been compiled by a more recent version of the Java Runtime (class file version 54.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(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)
2. 尝试办法
-
使用命令行编译也是不行
-
检查了我的版本之后发现环境变量是没有错误的:
3. 解决办法
- 看报错的信息是编译器的版本有冲突
king/HelloWorld has been compiled by a more recent version of the Java Runtime (class file version 54.0), this version of the Java Runtime only recognizes class file versions up to 52.0
于是就开始查资料
3.1 解决方法:
Project右键->Properties->Java Compiler->Configure Workspace Setting
3.2 测试结果成功
- 终于好了,我的HelloWorld测试出来了