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
371 views
in Technique[技术] by (71.8m points)

java - 如何修复java.lang.UnsupportedClassVersionError:不支持的major.minor版本(How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version)

I am trying to use Notepad++ as my all-in-one tool edit, run, compile, etc.

(我正在尝试使用Notepad ++作为我的多合一工具进行编辑,运行,编译等。)

I have JRE installed, and I have setup my path variable to the .../bin directory.

(我已经安装了JRE ,并且已将路径变量设置到.../bin目录。)

When I run my "Hello world" in Notepad++, I get this message:

(当我在Notepad ++中运行“ Hello world”时,出现以下消息:)

java.lang.UnsupportedClassVersionError: test_hello_world :
 Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
       .........................................

I think the problem here is about versions;

(我认为这里的问题是关于版本的。)

some versions of Java may be old or too new.

(Java的某些版本可能太旧或太新。)

  1. How do I fix it?

    (我如何解决它?)

  2. Should I install the JDK, and setup my path variable to the JDK instead of JRE?

    (我应该安装JDK,并将路径变量设置为JDK而不是JRE吗?)

  3. What is the difference between the PATH variable in JRE or JDK?

    (JRE或JDK中的PATH变量之间有什么区别?)

  ask by ERJAN translate from so

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

1 Reply

0 votes
by (71.8m points)

The version number shown describes the version of the JRE the class file is compatible with.

(显示的版本号描述了与类文件兼容的JRE的版本。)

The reported major numbers are:

(报告的主要数字是:)

Java SE 13 = 57,
Java SE 12 = 56,
Java SE 11 = 55,
Java SE 10 = 54,
Java SE 9 = 53,
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

(Source: Wikipedia )

((来源: 维基百科 ))

To fix the actual problem you should try to either run the Java code with a newer version of Java JRE or specify the target parameter to the Java compiler to instruct the compiler to create code compatible with earlier Java versions.

(要解决实际问题,您应该尝试使用Java JRE的较新版本运行Java代码,或为Java编译器指定目标参数,以指示编译器创建与Java早期版本兼容的代码。)

For example, in order to generate class files compatible with Java 1.4, use the following command line:

(例如,为了生成与Java 1.4兼容的类文件,请使用以下命令行:)

javac -target 1.4 HelloWorld.java

With newer versions of the Java compiler you are likely to get a warning about the bootstrap class path not being set.

(使用较新版本的Java编译器,您可能会收到有关未设置引导程序类路径的警告。)

More information about this error is available in a blog post New javac warning for setting an older source without bootclasspath .

(有关此错误的更多信息,请参见博客文章New javac warning有关设置没有bootclasspath的较旧源的警告 。)


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

...