Java 即使修复了兼容性,也无法修复 Unsupported major.minor version 52.0
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24790834/
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
Can't fix Unsupported major.minor version 52.0 even after fixing compatibility
提问by Maple
When I try running my java .jar on another machine I get the error
当我尝试在另一台机器上运行我的 java .jar 时出现错误
Unsupported major.minor version 52.0
不支持的 Major.minor 版本 52.0
I compiled my program using the jdk 1.6 and my machine (separate one) has java 7 installed.
我使用 jdk 1.6 编译了我的程序,并且我的机器(单独的)安装了 java 7。
This is the java version my machine is running:
这是我的机器运行的 Java 版本:
Here are the settings in my IDE (Eclipse Lunar)
这是我的 IDE (Eclipse Lunar) 中的设置
Why am I still getting an unsupported error?
为什么我仍然收到不受支持的错误?
I did check my run configuration and change it to jre6, but when I do I can't even run my program in the IDE.
我确实检查了我的运行配置并将其更改为 jre6,但是当我这样做时,我什至无法在 IDE 中运行我的程序。
Note: I would like my program to work with jdk 6, if that is not possible jdk 7.
注意:如果无法使用 jdk 7,我希望我的程序可以与 jdk 6 一起使用。
My Class Path:
我的课程路径:
采纳答案by Facepalmed
I agree with chrylis: you believe you changed your project's compliance settings but probably you didnt.
我同意 chrylis:您认为您更改了项目的合规性设置,但您可能没有。
Right click on your project and:
右键单击您的项目,然后:
- Java / Build Path : Go to Libraries tab and ensure yourself that you are really using jre6
- Java / Compiler : Ensure yourself that you have selected 1.6 compliance
- Java / 构建路径:转到库选项卡并确保您确实在使用 jre6
- Java/编译器:确保自己选择了 1.6 合规性
By the way you can "tell" eclipse that jre8 is 1.6 compliance clicking on Window/Preferences/Java/Installed JREs/Execution Environment and selecting in the left panel, Execution Environments, JavaSE-1.6 and in the Compatible JRE's panel, jre8
顺便说一下,您可以“告诉”eclipse jre8 符合 1.6 合规性,单击 Window/Preferences/Java/Installed JREs/Execution Environment 并在左侧面板中选择 Execution Environments JavaSE-1.6 和 Compatible JRE 的面板 jre8
回答by ct.tan
回答by Gobinath Mani
The error happens when you have compiled with higher version of Java and it is been tried to run with lower version of JRE. Even with minor version mismatch you would have this issue
当您使用更高版本的 Java 编译并尝试使用较低版本的 JRE 运行时,会发生错误。即使小版本不匹配,您也会遇到此问题
I had issue compiling with JDK 1.8.0_31 and it was run with jdk1.8.0_25 and was displaying the same error. Once either the target is updated to higher version or compiled with same or lesser version would resolve the issue
我在用 JDK 1.8.0_31 编译时遇到问题,它是用 jdk1.8.0_25 运行的,并显示相同的错误。一旦目标更新到更高版本或使用相同或更低版本编译将解决问题
回答by espinchi
Are you using retrolambda? If so, just do JAVA_HOME=$JAVA8_HOME
.
你在使用retrolambda吗?如果是这样,就这样做JAVA_HOME=$JAVA8_HOME
。
Source: https://github.com/evant/gradle-retrolambda/issues/74
回答by Bryida
Hi I found this linkthat helped me understand the issue. Hope it is useful. Version released so far are
嗨,我发现这个链接可以帮助我理解这个问题。希望它有用。到目前为止发布的版本是
- Java SE 8 = 52,
- Java SE 7 = 51,
- Java SE 6.0 = 50,
- Java SE 5.0 = 49,
- JDK 1.4 = 48,
- JDK 1.3 = 47,
- JDK 1.2 = 46,
- JDK 1.1 = 45
- Java SE 8 = 52,
- Java SE 7 = 51,
- Java SE 6.0 = 50,
- Java SE 5.0 = 49,
- JDK 1.4 = 48,
- JDK 1.3 = 47,
- JDK 1.2 = 46,
- JDK 1.1 = 45
and from thata data it simply means
从那个数据来看,它只是意味着
Many people think why do you get a version mismatch error if Java is backward compatible. Well, its true that Java is backward compatible, which means you can run a Java class file or Java binary (JAR file) compiled in lower version (java 6) into higher version e.g. Java 8, but it doesn't mean that you can run a class compiled using Java 7 into Java 5, Why? because higher version usually have features which are not supported by lower version.
许多人认为如果 Java 向后兼容,为什么会出现版本不匹配错误。好吧,Java 确实是向后兼容的,这意味着您可以将在较低版本 (java 6) 中编译的 Java 类文件或 Java 二进制文件(JAR 文件)运行到较高版本(例如 Java 8)中,但这并不意味着您可以将使用 Java 7 编译的类运行到 Java 5 中,为什么?因为高版本通常具有低版本不支持的功能。
Sometimes you may have more than one version of Java installed in you machine. Make sure the application you are running is pointing to the right or highest version available.
有时,您的机器中可能安装了多个版本的 Java。确保您正在运行的应用程序指向正确的或可用的最高版本。
回答by Abhijith
Its a silly problem, just make sure that the jdk and jre are latest version. This problem mainly occurs due to the automatic update of java(jre) and the jdk is not supported to that version, this makes problem.
这是一个愚蠢的问题,只需确保 jdk 和 jre 是最新版本。这个问题主要是因为java(jre)自动更新,jdk不支持那个版本,所以出问题了。
回答by Sabextc10
I Encounter similar issue while doing development on Android Studio 2.2.
我在 Android Studio 2.2 上进行开发时遇到了类似的问题。
My Machine Configuration -
我的机器配置 -
- JDK version 1.7.0_79 installed
- JDK version 1.8.0_101 installed
- Environment variable contains : JAVA_HOME = 1.7.0_79 JDK path and same is added to path variable
- Project SDK Location = C:\Program Files\Java\jdk1.8.0_101
- 已安装 JDK 版本 1.7.0_79
- 已安装 JDK 版本 1.8.0_101
- 环境变量包含:JAVA_HOME = 1.7.0_79 JDK 路径,同样添加到路径变量
- 项目 SDK 位置 = C:\Program Files\Java\jdk1.8.0_101
I then made below changes - 1. Uninstall JDK 1.7.0_79 2. Updated JAVA_HOME = 1.8.0_101 JDK path (Similar to SDK Location)
然后我做了以下更改 - 1. 卸载 JDK 1.7.0_79 2. 更新 JAVA_HOME = 1.8.0_101 JDK 路径(类似于 SDK 位置)
Now i am able to compile and run my application successfully , no more Unsupported major.minor version 52.0 Error
现在我可以成功编译和运行我的应用程序,不再出现 Unsupported major.minor version 52.0 错误
回答by Ram Achanta
Right Click on Project, Properties ---> Java Compiler ( on same page change compiler Compliance Level to 1.6 (or) 1.7 (or) 1.8 ( match with your JAVA_HOME)
右键单击项目,属性 ---> Java 编译器(在同一页面上将编译器合规性级别更改为 1.6(或)1.7(或)1.8(与您的 JAVA_HOME 匹配)
回答by Esmaeil MIRZAEE
First of all thank you for all above answers. However, I use Intellij Idea for daily basis. So, I hope my answer will help others.
首先感谢以上所有回答。但是,我每天都使用 Intellij Idea。所以,我希望我的回答能帮助其他人。
Run your favourite terminal or command line. Then check your java version by running command
运行您最喜欢的终端或命令行。然后通过运行命令检查您的 Java 版本
java -version
Then in Intellij press
然后在 Intellij 按
Ctrl+Alt+Shift+S
Ctrl+ Alt+ Shift+S
in the
在里面
Project Settings
tab under
标签下
Project SDK
choose appropriate java version. Lastly, rerun your code.
选择合适的java版本。最后,重新运行您的代码。
回答by Pravin Ghorle
I had also same issue. I solved this problem by updating my system jdk. Previously i used jdk7.0 and now it is updated to jdk8.0. find below link to download the updated jdk with new version. it help me to solve my problem.
我也有同样的问题。我通过更新我的系统 jdk 解决了这个问题。以前我用的是jdk7.0,现在更新到jdk8.0。找到以下链接以下载具有新版本的更新的 jdk。它帮助我解决我的问题。
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html