java.lang.UnsupportedClassVersionError:.class 文件中的错误版本号? [英] java.lang.UnsupportedClassVersionError: Bad version number in .class file?

查看:20
本文介绍了java.lang.UnsupportedClassVersionError:.class 文件中的错误版本号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我包含一个必须从源代码编译的开源库时,我收到此错误.现在,网络上的所有建议都表明代码在一个版本中编译并在另一个版本中执行(新旧).但是,我的系统上只有一个版本的 JRE.如果我运行命令:

I am getting this error when I include an opensource library that I had to compile from source. Now, all the suggestions on the web indicate that the code was compiled in one version and executed in another version (new on old). However, I only have one version of JRE on my system. If I run the commands:

$ javac -version
javac 1.5.0_18

$ java -version
java version "1.5.0_18"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_18-b02)
Java HotSpot(TM) Server VM (build 1.5.0_18-b02, mixed mode)

并在 Eclipse 中检查 java 库的属性,我得到 1.5.0_18

and check in Eclipse for the properties of the java library, I get 1.5.0_18

因此,我必须得出结论,类本身内部的其他东西正在抛出异常??这可能吗?

Therefore, I have to conclude something else, internal to a class itself, is throwing the exception?? Is that even possible?

推荐答案

我了解到像这样的错误消息通常是正确的.当它不可能(在您看来)是所报告的错误所说的内容时,您会去寻找另一个区域的问题……结果几个小时后才发现原来的错误消息确实是正确的.

I've learned that error messages like this are usually right. When it couldn't POSSIBLY (in your mind) be what the error being reported says, you go hunting for a problem in another area...only to find out hours later that the original error message was indeed right.

由于您使用的是 Eclipse,我认为 Thilo 是对的.您收到此消息的最可能原因是您的一个项目正在编译 1.6 类.如果系统上只有 1.5 JRE 没有关系,因为 Eclipse 有自己的编译器(不是 javac),并且只需要 1.5 JRE 即可编译 1.6 类.这可能很奇怪,需要取消选中设置才能允许这样做,但我只是设法做到了.

Since you're using Eclipse, I think Thilo has it right The most likely reason you are getting this message is because one of your projects is compiling 1.6 classes. It doesn't matter if you only have a 1.5 JRE on the system, because Eclipse has its own compiler (not javac), and only needs a 1.5 JRE to compile 1.6 classes. It may be weird, and a setting needs to be unchecked to allow this, but I just managed to do it.

对于有问题的项目,检查项目属性(通常是 Alt+Enter),Java 编译器部分.这是配置为编译 1.6 但只有 1.5 JRE 的项目的图像.

For the project in question, check the Project Properties (usually Alt+Enter), Java Compiler section. Here's an image of a project configured to compile 1.6, but with only a 1.5 JRE.

这篇关于java.lang.UnsupportedClassVersionError:.class 文件中的错误版本号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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