質問

i have java version "1.6.0_45" and javac 1.7.0_51 when i run my file as javac -source 1.6 Mouse.java then it show error this warning: [options] bootstrap class path not set in conjunction with -source 1.6 1 warning and when i run simple java Mouse then it show error Exception in thread "main" java.lang.UnsupportedClassVersionError: Mouse : Unsupported major.minor version 51.0.

役に立ちましたか?

解決

java.lang.UnsupportedClassVersionError: Mouse : Unsupported major.minor version 51.0

That error is caused by incompatible Java versions. You're most likely trying to run something compiled by a newer Java version with an older Java version. You should check your Java versions. 51.0 is the newer class file format which is supported by JDK7

他のヒント

You are compiling with 1.7 resulting in 1.7 code. You are trying to use Java 1.6 to execute said code. Doesn't work.

Edit: Either compile with 1.6 (if possible) or use > 1.7 compatible JRE to execute your code.

You told javac that your source code should be compatible with Java 6 (i.e. it should not use Java 7 specific features like try-with-resources or the diamond operator).

But you didn't tell it to compile class files compatible with Java 6. That is done using the -target 1.6 option.

Quite frankly, I would use the JDK 1.6 to compile your classes if you want the sourcecode and the target class files to be compatible with 1.6. That would guarantee (as the warning message you get tells you) that your code is also not using JDK classes and methods that have been introduced in Java 7.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top