Error " Unsupported major.minor version " in Java
When trying to run a class made in java , the following error message appears:
Java.lang.UnsupportedClassVersionError: Myclase (Unsupported major.minor version 50.0)
What does this error message mean?
2 answers
This error is because from your computer's default jvm (Java Virtual Machine), you are trying to run a class that was compiled into a version of the JDK (Java Development Kit) that is higher than the JVM (for example, trying to run a class compiled into JDK 1.6 with JVM 1.4).
If you want to check the version of the conflicting class, run the Command javap
which is the decompiler that comes included in the JDK, running it from %JAVA_HOME%\bin
(it is recommended to do it from the latest version of the JDK).
For example, if you want to know in which version of Java the Class MiClase.class
is compiled, run the following commands:
-
javap -verbose MiClase.class | findstr "major"
which would return something like:Major version: 50
-
javap -verbose MiClase.class | findstr "minor"
which would return something like:Minor version: 0
Thus the equivalences between Java versions and their 'major version' are as follows to date:
Java 1.2 corresponds to major version 46
Java 1.3 corresponds to major version 47
Java 1.4 corresponds to major version 48
Java 5 corresponds to major version 49
Java 6 corresponds to major version 50
Java 7 corresponds to major version 51
Java 8 corresponds to major version 52
(list Source )
This is a simple way to do this check with the javap
command, although there are more. If you know them, you are welcome to make your contribution as a comment to this answer.
You are running your program with a lower a version that it was compiled with.
Example, you compiled with 1.8 and try to run in version 1.7