java.lang.UnsupportedClassVersionError: Bad version number in .class file | About Publisher

java.lang.UnsupportedClassVersionError: Bad version number in .class file

java.lang.UnsupportedClassVersionError: Bad version number in .class file
[at java.lang.ClassLoader.defineClass1(Native Method)]
is an error that you may face in running a compiled java class file.


So as you can see from the stack trace, a class has not been loaded. But which class? The problem is this error message does not show the name of the failed .class, isn't it?

No, it is not.
This error is caused when you compile a .java file with one version of JDK and running the .class file with a different version of JVM.

Confused? You may say; same version is not required to compile and run.

Yes, that is true. But you can not run .class files that are compiled with a newer version than the JVM.

Say;

javac (compile) - version: X
java (run) - version: Y
If X is newer than Y; then you may face this issue at runtime.

Now you know how to solve this issue, isn't it?
Share this article please, on :
Share on fb Tweet Share on G+

0 Response to "java.lang.UnsupportedClassVersionError: Bad version number in .class file"

Post a Comment