Java 编译时出现异常:错误的版本 50.0,应该是 49.0

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1766216/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 22:25:28  来源:igfitidea点击:

Exception while compiling: wrong version 50.0, should be 49.0

javaexceptionjxl

提问by i2ijeya

I am working an application with JXL API and when i tried compiling using eclipse IDE, it's working fine and the same is not compiling when i am trying to compile in Command prompt and showing the below exception..

我正在使用 JXL API 工作一个应用程序,当我尝试使用 eclipse IDE 进行编译时,它工作正常,并且当我尝试在命令提示符下编译并显示以下异常时,同样没有编译..

Extract.java:6: cannot access jxl.read.biff.BiffException bad class file: C:\Program Files\Java\jdk1.5.0_01\jre\lib\ext\jxl.jar(jxl/read/biff/BiffException.class)
class file has wrong version 50.0, should be 49.0
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
import jxl.read.biff.BiffException;
                     ^
1 error

EDIT:

编辑:

I am able to executing using JDK 1.6. Since JDK 1.6 must also be compatible with lower versions, why doesn't it support the class files which were compiled in JDK 1.5.

我可以使用 JDK 1.6 执行。既然JDK 1.6也要兼容低版本,为什么不支持JDK 1.5编译的class文件呢?

采纳答案by OscarRyz

The library you're using was compiled with Java 6

您使用的库是用 Java 6 编译的

Your compiler is Java 5 that's why it doesn't understand that format.

您的编译器是 Java 5,这就是它不理解该格式的原因。

To fix it you have to get a 1.5 version of the library or upgrade your compiler to 1.6 I suggest the later.

要修复它,您必须获得 1.5 版本的库或将您的编译器升级到 1.6 我建议稍后。

回答by JERiv

Check you class path in eclipse and make sure that its the same class path your compiling to in the command prompt, also check your library imports

在 eclipse 中检查您的类路径,并确保它与您在命令提示符中编译到的类路径相同,同时检查您的库导入

回答by atk

Per http://www.jnode.org/node/2140...

每个http://www.jnode.org/node/2140...

Submitted by Stephen Crawley on Fri, 11/30/2007 - 07:15.

I suspect that you are mixing code compiled with different versions of Java. Class file version 50.0 is used by Java 6.0, and 49.0 is used by Java 5.0.

Try doing a "build clean" to get rid of all existing class files, followed by a regular build.

JNode is being developed using Java 6.0 only. Last time I tried, it didn't build using Java 5.0 (aka 1.5). (It is a problem with the program that builds the JNode boot image.)

Stephen Crawley 于周五,11/30/2007 - 07:15 提交。

我怀疑您正在混合使用不同版本的 Java 编译的代码。Java 6.0 使用类文件版本 50.0,Java 5.0 使用 49.0。

尝试执行“构建清理”以删除所有现有的类文件,然后进行常规构建。

JNode 仅使用 Java 6.0 开发。上次我尝试时,它没有使用 Java 5.0(又名 1.5)构建。(这是构建 JNode 启动映像的程序的问题。)

Try changing the builder in Eclipse. If you're using 3.4, it's Project - Properties - Java Compiler - Enable Project Specific Settings - Compiler Compliance Level = 1.6. You'll prolly also need to have JRE 1.6 installed, as well.

尝试在 Eclipse 中更改构建器。如果您使用的是 3.4,则为Project - Properties - Java Compiler - Enable Project Specific Settings - Compiler Compliance Level = 1.6。您还需要安装 JRE 1.6。

回答by Luthoz

this could be that in you IDE you point to latest version of JDK but when you build your program outside the IDE(maybe with maven) your java_home is the older version to the one on your IDE.

这可能是因为在您的 IDE 中您指向最新版本的 JDK,但是当您在 IDE 之外(可能使用 maven)构建您的程序时,您的 java_home 是您 IDE 上的旧版本。

回答by Chandrasekhar Rajoli

It means that, you have compiled that class with Java 6 and trying to execute with Java 5.

这意味着,您已经使用 Java 6 编译了该类并尝试使用 Java 5 执行。

Solution :

解决方案 :

If your using ant, execute below steps on the project root directory

如果您使用 ant,请在项目根目录执行以下步骤

  1. ant clean
  2. ant deploy
  1. 蚂蚁清洁
  2. 蚂蚁部署

If your using eclipse, just clean the workspace(remove the class files which were compiled with Java6) and build again

如果您使用 eclipse,只需清理工作区(删除用 Java6 编译的类文件)并再次构建