Java 不支持的 Major.minor 版本 52.0

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

Unsupported major.minor version 52.0

javaappletversionunsupported-class-version

提问by user3397452

Pictures:

图片:

Command Prompt showing versionsCommand Prompt showing versions

命令提示符显示版本命令提示符显示版本

Picture of errorPicture of error

错误图片错误图片

Hello.java

你好.java

import java.applet.Applet;
import java.awt.*;

public class Hello extends Applet {

    // Java applet to draw "Hello World"
    public void paint (Graphics page) {
        page.drawString ("Hello World!", 50, 50);
    }
}

Hello.html

你好.html

<HTML>
    <HEAD>
        <TITLE>HelloWorld Applet</TITLE>
    </HEAD>

    <BODY>
        <APPLET CODE="Hello.class" WIDTH=300 HEIGHT=150>
        </APPLET>
    </BODY>
</HTML>

Error

错误

Hello : Unsupported major.minor version 52.0

What may the problem be?

可能是什么问题?

回答by Andrew Thompson

The smartway to fix that problem is to compile using the latest SDK and use the cross compilation optionswhen compiling. To use the options completely correctlyrequires the rt.jarof a JRE (not JDK) of the target version.

解决该问题的明智方法是使用最新的 SDK 进行编译,并在编译时使用交叉编译选项。要完全正确地使用这些选项需要目标版本rt.jar的 JRE(而不是 JDK)。

Given the nature of that applet, it looks like it could be compiled for use with Java 1.1.

鉴于该小程序的性质,它看起来可以编译为与 Java 1.1 一起使用。

回答by Analyst

I had the same problem... a JDK and plug-in version conflict.

我遇到了同样的问题……JDK 和插件版本冲突。

I compiled using 1.8 ... the latest one, and that message started to appear. So I've searched for the JRE 7 (http://www.oracle.com/technetwork/java/javase/downloads/server-jre7-downloads-1931105.html)... and installed it... again... Now 1.8 and 1.7 in the same computer.

我使用 1.8 ... 最新版本进行编译,并且该消息开始出现。所以我搜索了 JRE 7 ( http://www.oracle.com/technetwork/java/javase/downloads/server-jre7-downloads-1931105.html)...并安装它...再次... . 现在1.8和1.7在同一台电脑上。

Using NetBeans, and compiling, and targeting to version 1.7, fixed my problem.

使用 NetBeans,编译并定位到 1.7 版,解决了我的问题。

回答by Eduardo Dennis

If you're using the NetBeans IDE, right click on the project and choose Propertiesand go to sources, and you can change the Source/Binary Format to a lower JDK version.

如果您使用的是 NetBeans IDE,请右键单击该项目并选择Properties并转到sources,您可以将 Source/Binary Format 更改为较低的 JDK 版本。

Enter image description here

在此处输入图片说明

回答by olammy

You will need to change your compiler compliance level back to 1.7 in your IDE.

您需要在 IDE 中将编译器合规性级别更改回 1.7。

This can be done in the preferences settings of your IDE. For example, in Eclipse go to menu WindowsPreferences, select Java, and expand it. Then select Compilerand change the compliance level to 1.7. I am sure this will work from there.

这可以在 IDE 的首选项设置中完成。例如,在 Eclipse 中,转到菜单WindowsPreferences,选择 Java,然后展开它。然后选择Compiler并将合规性级别更改为 1.7。我相信这会从那里工作。

回答by Val

This occurred to me when I installed a fresh Java 1.8, but left the old command line interpreter open.

当我安装新的 Java 1.8 时,我想到了这一点,但让旧的命令行解释器保持打开状态。

It had an old path and kept on executing the application with Java 1.7 whereas project was already built with Java 1.8.

它有一条旧路径并继续使用 Java 1.7 执行应用程序,而项目已经使用 Java 1.8 构建。

回答by ZAIRI Oussama

You must run and compile your application with the same version of Java.

您必须使用相同版本的 Java 运行和编译您的应用程序。

If you're using Eclipse you should do 2 things:

如果您使用 Eclipse,您应该做两件事:

  1. In Eclipse, click on "Window > Preferences", and in the window that appears, on the left side, under "Java", click on "Installed JREs", click on "Add..."and navigate to the folder that contains the JDK.

  2. Right-click on your project and click on "Properties", in the window that appears, on the left side, click on "Java Compiler"and uncheck "Use compliance from execution environment on the Java Build Path", this allows you to choose in the the list "Compiler compilance level"the same version that you set in the previous step.

  1. 在 Eclipse 中,单击"Window > Preferences",然后在出现的窗口中,在左侧的"Java" 下,单击"Installed JREs",单击"Add..."并导航到包含JDK。

  2. 右键单击您的项目并单击“属性”,在出现的窗口中,在左侧单击“Java 编译器”并取消选中“在 Java 构建路径上使用执行环境的合规性”,这允许您选择在“Compiler compilance level”列表中与您在上一步中设置的版本相同。

回答by ct.tan

You may want to check your Run Configurationssetting if you're using Eclipse v4.4 (Luna) and have already completed all steps mentioned above.

如果您使用的是 Eclipse v4.4 (Luna) 并且已经完成了上述所有步骤,您可能需要检查您的运行配置设置。

There could be several possibilities that cause this error. The root cause is a mismatch of the project require compilation in JDK1.8/JRE8 while the environment compiler is JDK1.7/JRE7.

可能有多种可能导致此错误。根本原因是项目要求编译在JDK1.8/JRE8,而环境编译器是JDK1.7/JRE7不匹配。

You can check my blog postto go through all your settings are correct.

您可以查看我的博客文章以检查所有设置是否正确。

回答by ClaireWang

You need to use JDK 1.7.0 rather than JDK 1.8.0.

您需要使用 JDK 1.7.0 而不是 JDK 1.8.0。

To make sure it, you need to delete JDK 1.8.0 on your computer.

为了确保它,您需要删除计算机上的 JDK 1.8.0。

If you use Mac, you need to delete:

如果您使用Mac,则需要删除:

/Library/Java/JavaVirtualMachines/jdk.jdk

/库/Java/JavaVirtualMachines/jdk.jdk

/Library/PreferencePanes/JavaControlPanel.prefPane

/Library/PreferencePanes/JavaControlPanel.prefPane

/Library/Internet Plug-Ins/JavaAppletPlugin.plugin

/Library/Internet Plug-Ins/JavaAppletPlugin.plugin

Then, you need to reinstall JDK 1.7.0, and you will succeed to generate the .jar file.

然后,您需要重新安装JDK 1.7.0,您将成功生成.jar 文件。

回答by Lior Ohana

I had Java 1.7 & 1.8 installed (with SBT 2.4 that requires Java 1.8). Even though my project was linked to Java 1.8, I had to change the JAVA_HOME environment variable to point 1.8. Finally, problem solved.

我安装了 Java 1.7 和 1.8(使用需要 Java 1.8 的 SBT 2.4)。即使我的项目链接到 Java 1.8,我也必须将 JAVA_HOME 环境变量更改为指向 1.8。终于,问题解决了。

回答by Bevor

None of these answers helped me, but I found a solution.
I had a webproject used in Wildfly 8.2, built with Maven, source and target was set to 1.8 on maven-compiler-plugin, as well as all Eclipse and Maven settings were set to Java 1.8. The problem was that Wildfly 8.2 cannot handle Java 1.8, so I had to set everything to 1.7 and it worked.

这些答案都没有帮助我,但我找到了解决方案。
我在 Wildfly 8.2 中使用了一个 web 项目,用 Maven 构建,源和目标在 maven-compiler-plugin 上设置为 1.8,并且所有 Eclipse 和 Maven 设置都设置为 Java 1.8。问题是 Wildfly 8.2 无法处理 Java 1.8,所以我必须将所有内容都设置为 1.7 并且它起作用了。