Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
415 views
in Technique[技术] by (71.8m points)

java - 不支持的major.minor版本52.0 [重复](Unsupported major.minor version 52.0 [duplicate])

This question already has an answer here:

(这个问题已经在这里有了答案:)

Pictures:

(图片:)

命令提示符显示版本 Command Prompt showing versions

(命令提示符显示版本)

错误图片 Picture of error

(错误图片)

Hello.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 (Hello.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?

(可能是什么问题?)

  ask by user3397452 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The issue is because of Java version mismatch.

(问题是由于Java版本不匹配。)

Referring to the Wikipedia Java Class Reference :

(参考Wikipedia Java类参考 :)

  • Java SE 12 = 56 (0x38 hex)

    (Java SE 12 = 56(十六进制0x38))

  • Java SE 11 = 55 (0x37 hex)

    (Java SE 11 = 55(十六进制0x37))

  • Java SE 10 = 54

    (Java SE 10 = 54)

  • Java SE 9 = 53

    (Java SE 9 = 53)

  • Java SE 8 = 52

    (Java SE 8 = 52)

  • Java SE 7 = 51

    (Java SE 7 = 51)

  • Java SE 6.0 = 50

    (Java SE 6.0 = 50)

  • Java SE 5.0 = 49

    (Java SE 5.0 = 49)

  • JDK 1.4 = 48

    (JDK 1.4 = 48)

  • JDK 1.3 = 47

    (JDK 1.3 = 47)

  • JDK 1.2 = 46

    (JDK 1.2 = 46)

  • JDK 1.1 = 45

    (JDK 1.1 = 45)

These are the assigned major numbers.

(这些是分配的专业编号。)

The error regarding the unsupported major.minor version is because during compile time you are using a higher JDK and a lower JDK during runtime .

(关于不受支持的major.minor版本的错误是因为在编译期间,您在运行时使用的是较高的JDK,而使用的是较低的JDK 。)

Thus, the 'major.minor version 52.0' error is possibly because the jar was compiled in JDK 1.8, but you are trying to run it using a JDK 1.7 environment.

(因此,“ major.minor版本52.0”错误可能是因为jar是在JDK 1.8中编译的,但是您正在尝试使用JDK 1.7环境运行它。)

The reported number is the required number, not the number you are using.

(报告的号码是必需的号码,而不是您正在使用的号码。)

To solve this, it's always better to have the JDK and JRE pointed to the same version.

(为了解决这个问题,最好让JDK和JRE指向相同的版本。)

In IntelliJ IDEA,

(在IntelliJ IDEA中,)

  1. Go to Maven SettingsMavenImporting .

    (转到Maven设置Maven导入 。)

    Set the JDK for importer to 1.8.

    (将JDK for importer设置为1.8。)

  2. Go to Maven SettingsMavenRunner .

    (转到Maven设置Maven转轮 。)

    Set the JRE to 1.8.

    (将JRE设置为1.8。)

  3. Go to menu File* → Project StructureSDKs .

    (进入菜单文件*→ 项目结构SDK 。)

    Make sure the JDK home path is set to 1.8.

    (确保将JDK主目录路径设置为1.8。)

Restart IntelliJ IDEA.

(重新启动IntelliJ IDEA。)

Another approach which might help is by instructing IntelliJ IDEA which JDK version to start up with.

(另一种可能有用的方法是指示IntelliJ IDEA启动哪个JDK版本。)

Go to: /Applications/IntelliJ\ IDEA\ 15\ CE.app/Contents/Info.plist and replace the JVM version with:

(转到: / Applications / IntelliJ \ IDEA \ 15 \ CE.app/Contents/Info.plist并将JVM版本替换为:)

<key>JVMVersion</key>
<string>1.8*</string>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...