首页 > 解决方案 > JRE 和 Java 编译版本不匹配 Visual Code Studio

问题描述

我已经运行了一个程序,并且在更新 java 之后,我在尝试运行任何代码时得到了(编译工作正常)。我看过有类似问题的人,但他们似乎大多只是陈述正在发生的问题,并没有给我太多关于如何解决它的想法。

我尝试先重新安装java,但这似乎没有任何作用。接下来我查看了 JRE 本身,但它被设置为自动更新。只是为了确保我再次尝试查找更新,但没有任何结果。我还尝试了重新启动计算机和 Visual Code Studio 的基础知识。我没有尝试过的最重要的事情是我的 JDK,因为坦率地说,我不太了解如何设置它,并且担心我可能会破坏它。

c:\Users\kmaaf\Desktop\Coding Homework\PP3>java BenchmarkTimer
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: BenchmarkTimer 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)

甚至在今天早些时候,我正在使用的程序运行良好。只是在更新之后几乎完全出现了问题。感谢您提前给我的任何帮助或提示!

编辑:我正在使用命令提示符尝试运行我的代码。使用命令行它说我的 java 版本是 1.8.0_211-b12,而我的 JDK 声称是 11.0.02

标签: java

解决方案


我已经设法解决了!谢谢你的帮助!出于某种原因,我的计算机上有多个 java 副本;将它们全部删除,然后重新安装设法解决所有问题。感谢所有帮助过我的人!


推荐阅读