Java 类文件有错误的版本 52.0,应该是 50.0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28180915/
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 05:45:11  来源:igfitidea点击:

Class file has wrong version 52.0, should be 50.0

javaintellij-idea

提问by jaywayco

I'm trying to compile my project in IntelliJ idea. I'm using a class in an external jar file and on compilation receiving the above error.

我正在尝试在 IntelliJ 想法中编译我的项目。我在外部 jar 文件中使用一个类,并且在编译时收到上述错误。

I understand that it's saying the jar file was compiled with a newer Java version than that which IntelliJ is using. My question is how do I make them compatible? I have updated the Java on my Mac to 1.8 and when I run java -versionor javac -versionit confirms this.

我知道它是说 jar 文件是用比 IntelliJ 使用的 Java 版本更新的 Java 版本编译的。我的问题是如何使它们兼容?我已将 Mac 上的 Java 更新为 1.8,当我运行时java -versionjavac -version它确认了这一点。

What am I missing? (Apart from Java development experience)

我错过了什么?(除了Java开发经验)

采纳答案by Vlad Spreys

Select "File" -> "Project Structure".

选择“文件”->“项目结构”。

Under "Project Settings" select "Project"

在“项目设置”下选择“项目”

From there you can select the "Project SDK".

从那里您可以选择“项目 SDK”。

回答by Superdoggy

It means your Java runtime version is 1.8, but your compiler version (javac) is 1.6. To simply solve it, just retreat the Java version from 1.8 to 1.6.

这意味着您的 Java 运行时版本是 1.8,但您的编译器版本 (javac) 是 1.6。简单解决,只需将Java版本从1.8退到1.6即可。

But if you don't want to change the Java runtime version, then do the following steps:

但如果您不想更改 Java 运行时版本,则执行以下步骤:

  1. JAVA_HOME= "your jdk v1.8 folder path", to make sure jdk is also v1.8 and use java -version and javac -version again to ensure it
  2. Make sure IntelliJ 's compiler mode is set to compliant with v1.6 But i have tried that. it didn't solve my problem.
  1. JAVA_HOME= "your jdk v1.8 文件夹路径",确保jdk也是v1.8,再次使用 java -version 和 javac -version 来保证
  2. 确保 IntelliJ 的编译器模式设置为符合 v1.6 但我已经尝试过了。它没有解决我的问题。

回答by praneeth

i faced the same problem "Class file has wrong version 52.0, should be 50.0" when running java through ant... all i did was add fork="true"wherever i used the javactask and it worked...

我在通过 ant 运行 java 时遇到了同样的问题“类文件的版本错误为 52.0,应该是 50.0”...我所做的只是在我使用javac任务的任何地方添加fork="true"并且它工作...

回答by user3132194

Have got the same error as in header because of failed attempt to compile my project with java 8 and then reattempting to compile with java 6. Some classes where compiled at the first attempt with 8 and did not recompile with 6. Mixed classes did not compile then. Cleaning project solved the problem. This answer is not strictly relevant to the question, but could be useful for someone.

由于尝试使用 java 8 编译我的项目然后重新尝试使用 java 6 编译失败,因此出现与 header 中相同的错误。某些类在第一次尝试时使用 8 编译,但没有使用 6 重新编译。混合类没有编译然后。清洁工程解决了这个问题。这个答案与问题并不严格相关,但可能对某人有用。

回答by ADAM

In your IntelliJ idea find tools.jar replace it with tools.jar from yout JDK8

在你的 IntelliJ 想法中找到 tools.jar 用你的 JDK8 中的 tools.jar 替换它