How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
The version number shown describes the version of the JRE the class file is compatible with.
The reported major numbers are:
Java SE 18 = 62,
Java SE 17 = 61,
Java SE 16 = 60,
Java SE 15 = 59,
Java SE 14 = 58,
Java SE 13 = 57,
Java SE 12 = 56,
Java SE 11 = 55,
Java SE 10 = 54,
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 a blog post New javac warning for setting an older source without bootclasspath.
How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
The version number shown describes the version of the JRE the class file is compatible with.
The reported major numbers are:
Java SE 18 = 62,
Java SE 17 = 61,
Java SE 16 = 60,
Java SE 15 = 59,
Java SE 14 = 58,
Java SE 13 = 57,
Java SE 12 = 56,
Java SE 11 = 55,
Java SE 10 = 54,
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 a blog post New javac warning for setting an older source without bootclasspath.
What does 'Unsupported major.minor version 52.0' mean, and how do I fix it?
You don't need to change the compliance level here, or rather, you should but that's not the issue.
The code compliance ensures your code is compatible with a given Java version.
For instance, if you have a code compliance targeting Java 6, you can't use Java 7's or 8's new syntax features (e.g. the diamond, the lambdas, etc. etc.).
The actual issue here is that you are trying to compile something in a Java version that seems different from the project dependencies in the classpath.
Instead, you should check the JDK/JRE you're using to build.
In Eclipse, open the project properties and check the selected JRE in the Java build path.
If you're using custom Ant (etc.) scripts, you also want to take a look there, in case the above is not sufficient per se.
Problems fixing java.lang.UnsupportedClassVersionError: Unsupported major.minor version 52
UnsupportedClassVersionError
is always due to the fact that a class was compiled with a Java version greater than the Java version being used to run it.
When you have an IDE
, an app server like Tomcat
and other things, you may have several settings that must point to a JDK
(with the JAVA_HOME
environment variable being the most important). If they all point to the correct place, there's no problem, however there are possibilities for errors such as:
- Setting points to
JRE
instead ofJDK
This causes problems when there's a need for javac
which doesn't exist in the JRE
. For example Tomcat
needs javac
to compile things, so JRE
is not enough.
- Setting points to a different
JDK
than other settings
This causes the UnsupportedClassVersionError
, and then you need to find which setting is wrong. Often JAVA_HOME
points to the correct place, but a different setting points to an older JDK
. A common problem is having JAVA_HOME
point to Oracle's JDK and Tomcat pointing to OpenJDK
.
Since you can use -source
and -target
flags to compile for older versions, you don't need to keep more than one JDK on your system. Remove the old ones and the chances for mysterious errors diminish.
Unsupported major.minor version 52.0 in java
This is because On your system javac
utility is pointing to Java 1.8
but java
utility is pointing to Java 1.7
.
To resolve it do following:
Note: I'm assuming that you are working on Windows OS
.
- In
PATH
variable, remove the very first path, if it looks like...\Oracal\javapath
- Set
JDK_HOME
andJRE_HOME
forJava 1.7
java.lang.UnsupportedClassVersionError: Unsupported major.minor version 51.0
clearly, your Java runtime evnironment is different from that of compile time version
For me this solved the problem:
I have a 64-bit system with jdk1.7 (32bit) and jdk1.6 (64 bit) installed. Even though I had specified PATH and JAVA_HOME for jdk1.7, my java -version was 1.6
- I removed the folder in which jdk1.6 was installed
. The problem was gone. Apparently, a 64 bit system gave preference to jdk1.6(64bit) instead of jdk1.7(32bit)
For more info, refer: How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
Related Topics
How to Remove Repeated Elements from Arraylist
How to Import a Jar in Eclipse
Why Does Gson Fromjson Throw a Jsonsyntaxexception: Expected Begin_Object But Was Begin_Array
String Concatenation: Concat() VS "+" Operator
How to Get the Insert Id in Jdbc
Streamcorruptedexception: Invalid Type Code: Ac
What Are the Reasons Why Map.Get(Object Key) Is Not (Fully) Generic
How to Load a File from Resource Folder
How to Best Position Swing Guis
How to Get a Class Instance of Generic Type T
How to Read the Value of a Private Field from a Different Class in Java
Technically What Is the Main Difference Between Oracle Jdk and Openjdk
What Is Double Brace Initialization in Java
Java Logical Operator Short-Circuiting
Why Is Using a Wild Card With a Java Import Statement Bad
How to Use the Tostring Method in Java