I am getting this error, in my destination computer despite:
Why the UnsupportedClassVersionError
despite the three constraints, and solution for it?
Note: the file is a simple GUI front end code which works perfectly on the source, which used simple libraries from AWT and SWING
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Unfortunately, the fact is your main class was, in fact, compiled with a newer version of the Java compiler than you're running it with. That or your class file was somehow horribly corrupted in some other way. Check that you don't have multiple versions of java
and javac
installed and on your PATH
. You might also want to try passing -target 1.6
to javac; if you're running (for example) javac 1.7 this will instruct it to produce code compatible with Java 1.6.
Keep in mind that you can have different version of the JRE and JDK installed - depending on your PATH order, your system might choose Java 1.7 for javac
but Java 1.6 for java
.
Additionally, if you have any third-party libraries on your classpath, you should make sure they were not compiled with a newer version of Java as well. If your other classes didn't make use of the third-party library that may have masked the problem.