如何修复 java.lang.UnsupportedClassVersionError: Unsupported major.minor version [英] How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version

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

问题描述

我正在尝试使用 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: Unsupported major.minor version的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆