How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version

转自:https://stackoverflow.com/questions/10382929/how-to-fix-java-lang-unsupportedclassversionerror-unsupported-major-minor-versi

The version number shown describes the version of the JRE the class file is compatible with.

The reported major numbers are:

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

(Source: Wikipedia)

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.

For example, in order to generate class files compatible with Java 1.4, use the following command line:

javac -target 1.4 HelloWorld.java

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.

share improve this answer
 
143  
"The version number shown describe which version if Java was used to compile the code." No it does not.It shows the version of the JRE that the class file is compatible with. Using cross-compilation options you can use a 1.7 JDK to compile code with a class version of 1.1 (through 1.7). –  Andrew Thompson  Jan 10 '13 at 5:31 
73  
This answer does not explain how to fix it as the question asked? –  Jonathan Leung  Mar 5 '13 at 12:58
5  
This is a nice solution for compiling to a previous version from Eclipse directly: stackoverflow.com/a/16345710/2091700 –  Alphaaa  May 23 '13 at 14:03
17  
IN eclipse project=>Proerties=>java compiler; set "the compiler compliance level" to the version according to your jre or jdk. As for me, it's 1.6 for jre 1.6 –  Sam  Sep 25 '13 at 14:58 
4  
This may occur when compiler source is set in non-compliance with currently compiling JRE/JDK. For example i found the below values from eclipse .settings folder, org.eclipse.jdt.core.compiler.compliance=1.7, org.eclipse.jdt.core.compiler.source=1.7, org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7. And my compiler was 1.6.0_32. The problem was resolved after changing the values to 1.6. The issue originated after i copied the project from a different workspace where i was using JDK 1.7 :( –  Gana  Dec 22 '14 at 6:22 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值