问题描述
我正在尝试使用 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.
- 我该如何解决?
- 我是否应该安装 JDK,并将我的路径变量设置为 JDK 而不是 JRE?
- JRE和JDK中的
PATH
变量有什么区别?
- How do I fix it?
- Should I install the JDK, and setup my path variable to the JDK instead of JRE?
- 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 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!