如何修复 java.lang.UnsupportedClassVersionError:不支持的 major.minor

2023-08-24Java开发问题
12

本文介绍了如何修复 java.lang.UnsupportedClassVersionError:不支持的 major.minor 版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试使用 Notepad++ 作为我的多合一工具编辑、运行、编译等.

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

我已安装 JRE,并且已将路径变量设置为 .../bin 目录.

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

当我在 Notepad++ 中运行Hello world"时,我收到以下消息:

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

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)
       .........................................

我认为这里的问题在于版本;某些 Java 版本可能太旧或太新.

I think the problem here is about versions; some versions of Java may be old or too new.

  1. 我该如何解决?
  2. 我是否应该安装 JDK,并将我的路径变量设置为 JDK 而不是 JRE?
  3. JRE和JDK中的PATH变量有什么区别?
  1. How do I fix it?
  2. Should I install the JDK, and setup my path variable to the JDK instead of JRE?
  3. What is the difference between the PATH variable in JRE or JDK?

推荐答案

显示的版本号描述了类文件兼容的 JRE 的版本.

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

报告的主要数字是:

Java SE 17 = 61,
Java SE 16 = 60, 
Java SE 15 = 59,
Java SE 14 = 58,
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

(来源:维基百科)

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

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 1.4 兼容的类文件,请使用以下命令行:

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

javac -target 1.4 HelloWorld.java

使用较新版本的 Java 编译器,您可能会收到有关未设置引导类路径的警告.博文中提供了有关此错误的更多信息新的 javac 警告,用于设置较旧的源而不引导类路径.

With newer versions of the Java compiler you are likely to get a warning about the bootstrap class path not being set. More information about this error is available in a blog post New javac warning for setting an older source without bootclasspath.

这篇关于如何修复 java.lang.UnsupportedClassVersionError:不支持的 major.minor 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何使用 JAVA 向 COM PORT 发送数据?
How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)...
2024-08-25 Java开发问题
21

如何使报表页面方向更改为“rtl"?
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)...
2024-08-25 Java开发问题
19

在 Eclipse 项目中使用西里尔文 .properties 文件
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)...
2024-08-25 Java开发问题
18

有没有办法在 Java 中检测 RTL 语言?
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)...
2024-08-25 Java开发问题
11

如何在 Java 中从 DB 加载资源包消息?
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)...
2024-08-25 Java开发问题
13

如何更改 Java 中的默认语言环境设置以使其保持一致?
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)...
2024-08-25 Java开发问题
13