简体   繁体   English

Java中不受支持的major.minor 52.0异常

[英]Unsupported major.minor 52.0 exception in Java

Given such an exception: 给定这样一个例外:

java.lang.UnsupportedClassVersionError: com/sun/tools/javac/Main : Unsupported major.minor version 52.0

And I know this is because that the JDK and JRE are not compatible. 我知道这是因为JDK和JRE不兼容。 However, when I type in: 但是,当我输入:

which java

The output is: 输出为:

/usr/java/jdk1.6.0_24/bin/java

And when typing in: 并在输入时:

which javac

The output is: 输出为:

/usr/java/jdk1.6.0_24/bin/javac

It is the compatible in version. 它是兼容版本。 So what's the problem? 所以有什么问题?

The problem is typically caused by this sequence: 该问题通常是由以下顺序引起的:

  • Code is compiled with new JDK, and "target" set to current version of Java. 使用新的JDK编译代码,并将“目标”设置为Java的当前版本。

  • Attempt to run the code with an older JDK or JRE. 尝试使用较旧的JDK或JRE运行代码。

In this case, minor version 52 means that something has been compiled with a Java 8 JDK, and with Java 8 as the target platform, and that you are attempting to run it on an older JRE / JDK. 在这种情况下,次要版本52表示已经使用Java 8 JDK并将Java 8作为目标平台进行了编译,并且您试图在较旧的JRE / JDK上运行它。

You could also have gotten a JAR file from somewhere else that was compiled for Java 8. 您还可能从其他地方为Java 8编译了JAR文件。

To solve your problem, you need to figure out: 要解决您的问题,您需要弄清楚:

  • which class file or files have the version number problem (the exception message should tell you the first one ...), 哪个类文件存在版本号问题(异常消息应告诉您第一个……),

  • where the class file came from (from a JAR file? from the file system?), and then 类文件来自哪里(来自JAR文件?来自文件系统?),然后

  • how come it was compiled with Java 8 though you thought you were compiling with Java 6. 尽管您认为自己正在使用Java 6进行编译,但它是如何用Java 8进行编译的。

It is an indisputable fact that the class that won't load was compiled using Java 8 (or later) compiler. 毋庸置疑的事实是,无法加载的类使用Java 8(或更高版本)编译器编译的。 You need to figure out why, and then either recompile it with the older JDK, or run it with Java 8. 您需要弄清楚原因,然后使用较旧的JDK重新编译, 使用Java 8运行它。

它说版本为52.0,所以您应该安装Java 8。

Check if tools.jar used during compilation complies with the JRE set. 检查编译期间使用的tools.jar是否符合JRE集。 If you are on eclipse, verify the versions as: 如果您正在日食,请验证以下版本:

Goto Window->Preferences 转到窗口->首选项

  • Check Ant Runtime by selecting Runtime under Ant in the left pane. 通过选择左窗格中Ant下的Runtime来检查Ant Runtime。 Check the Global Entries under classpath tab. 检查“类路径”选项卡下的“全局条目”。 You can see the version in folder path. 您可以在文件夹路径中查看版本。

  • On the left pane check installed JREs under Java. 在左窗格中,检查Java下已安装的JRE。 Check the version. 检查版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM