已由更新版本的 Java Runtime 编译(类文件版本 57.0)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/58125830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 01:19:26  来源:igfitidea点击:

Has been compiled by a more recent version of the Java Runtime (class file version 57.0)

javaintellij-ideasdk

提问by nobism

I get this problem Using IntelliJ. But I have the newest version of everything newly installed on my system.

我在使用 IntelliJ 时遇到了这个问题。但是我的系统上新安装的所有东西都是最新版本。

... has been compiled by a more recent version of the Java Runtime (class file version 57.0), this version of the Java Runtime only recognizes class file versions up to 52.0

...已由更新版本的 Java Runtime(类文件版本 57.0)编译,此版本的 Java Runtime 仅识别最高 52.0 的类文件版本

I've set:

我已经设置:

PATH as C:\Program Files\Java\jdk-13 JAVA_HOME as: C:\Program Files\Java\jdk-13 JRE_HOME as: C:\Program Files\Java\jre1.8.0_221

PATH 为 C:\Program Files\Java\jdk-13 JAVA_HOME 为:C:\Program Files\Java\jdk-13 JRE_HOME 为:C:\Program Files\Java\jre1.8.0_221

I've set the path, tried to find a change in the Project structure

我已经设置了路径,试图在项目结构中找到变化

COMPLETE ERROR MESSAGE:

完整的错误信息:

H:7-JAVA\HelloWorld\src>java com.codewithmosh.Main
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/codewithmosh/Main has been compiled by a more recent version of the Java Runtime (class file version 57.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.access0(Unknown Source)
        at java.net.URLClassLoader.run(Unknown Source)
        at java.net.URLClassLoader.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)

回答by CrazyCoder

You need to double check the PATHenvironment setting. C:\Program Files\Java\jdk-13you currently have there is not correct. Please make sure you have the binsubdirectory for the latest JDK version at the top of the PATHlist.

您需要仔细检查PATH环境设置。C:\Program Files\Java\jdk-13您目前的情况不正确。请确保您binPATH列表顶部有最新 JDK 版本的子目录。

java.exeexecutable is in C:\Program Files\Java\jdk-13\bindirectory, so that is what you need to have in PATH.

java.exe可执行文件在C:\Program Files\Java\jdk-13\bin目录中,所以这是你需要在PATH.

Use this toolto quickly verify or edit the environment variables on Windows. It allows to reorder PATHentries. It will also highlight invalid paths in red.

使用此工具可在 Windows 上快速验证或编辑环境变量。它允许重新排序PATH条目。它还将以红色突出显示无效路径。

If you want your code to run on lower JDK versions as well, change the target bytecode version in the IDE. See this answerfor the relevant screenshots.

如果您还希望您的代码在较低的 JDK 版本上运行,请在 IDE 中更改目标字节码版本。有关相关屏幕截图,请参阅此答案

See also this answerfor the Java class file versions. What happens is that you build the code with Java 13 and 13 language level bytecode (target) and try to run it with Java 8 which is the first (default) Java version according to the PATHvariable configuration.

有关Java 类文件版本,另请参阅此答案。发生的情况是,您使用 Java 13 和 13 语言级别字节码(目标)构建代码并尝试使用 Java 8 运行它,这是根据PATH变量配置的第一个(默认)Java 版本。

The solution is to have Java 13 bindirectory in PATHabove or instead of Java 8. On Windows you may have C:\Program Files (x86)\Common Files\Oracle\Java\javapathadded to PATHautomatically which points to Java 8 now:

解决方案是将 Java 13bin目录放在PATH上面或代替 Java 8。在 Windows 上,您可能已经自动C:\Program Files (x86)\Common Files\Oracle\Java\javapath添加了PATH现在指向 Java 8 的目录:

javapath

路径

If it's the case, remove the highlighted part from PATHand then logout/login or reboot for the changes to have effect. You need to Restart as administratorfirst to be able to edit the System variables (see the button on the top right of the system variables column).

如果是这种情况,请从中删除突出显示的部分PATH,然后注销/登录或重新启动以使更改生效。您需要首先以管理员身份重新启动才能编辑系统变量(请参阅系统变量列右上角的按钮)。

回答by Karan

I also encountered similar problem which is asked here. The issue was that some applications come with their own JRE and sometimes the installed JDK appears at lower priority level in environment path. Now there are two options:

我也遇到了类似的问题,这里被问到。问题是某些应用程序带有自己的 JRE,有时安装的 JDK 在环境路径中的优先级较低。现在有两个选择:

  1. Uninstall the other application which has their own JDK/JRE.
  2. Sometimes it is not possible to remove the other application, which was my case. So I moved JDk installed by me to higher priority level in environment path.
  1. 卸载具有自己的 JDK/JRE 的其他应用程序。
  2. 有时无法删除其他应用程序,这就是我的情况。所以我将我安装的 JDK 移动到环境路径中更高的优先级。

enter image description here

在此处输入图片说明

I also removed the path as suggested by @CrazyCoder

我还删除了@CrazyCoder 建议的路径

回答by S Kumar

i am facing same problem when i installed jre by Oracles and solved this problem after my research.

当我通过 Oracles 安装 jre 并在我研究后解决了这个问题时,我遇到了同样的问题。

i am moved the environment path C:\Program Files (x86)\Common Files\Oracle\Java\javapathBellow of H:\Program Files\Java\jdk-13.0.1\bin

我被感动的环境路径 C:\Program Files (x86)\Common Files\Oracle\Java\javapath波纹管H:\Program Files\Java\jdk-13.0.1\bin

Like this:-

像这样:-

Path

H:\Program Files\Java\jdk-13.0.1\bin
C:\Program Files (x86)\Common Files\Oracle\Java\javapath

小路

H:\Program Files\Java\jdk-13.0.1\bin
C:\Program Files (x86)\Common Files\Oracle\Java\javapath

OR

或者

Path

%JAVA_HOME%
%JRE_HOME%

小路

%JAVA_HOME%
%JRE_HOME%

回答by Memin

I had similar problem with IntelliJwhen tried to run some Groovy scripts. Here is how I solved it.

我在尝试运行一些 Groovy 脚本时遇到了与IntelliJ类似的问题。这是我解决它的方法。

Go to "Project Structure"-> "Project" -> "Project language level" and select "SDK default". This should use the same SDK for all project modules.

转到“项目结构”->“项目”->“项目语言级别”并选择“SDK默认”。这应该为所有项目模块使用相同的 SDK。