如何修复java.lang.UnsupportedClassVersionError:不支持的major.minor版本 [英] How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version

查看:945
本文介绍了如何修复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 version of Java may be old or too new.


  1. 如何解决?

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

  3. PATH 变量之间有什么区别?在JRE或JDK中?

  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 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公司de使用较新版本的Java JRE或指定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警告,用于设置没有bootclasspath的旧源代码

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 blog post New javac warning for setting an older source without bootclasspath.

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

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