Class file has wrong version 52.0, should be 50.0

JavaIntellij Idea

Java Problem Overview


I'm trying to compile my project in IntelliJ idea. I'm using a class in an external jar file and on compilation receiving the following error.

Class file has wrong version 52.0, should be 50.0

I understand that it's saying the jar file was compiled with a newer Java version than that which IntelliJ is using. My question is how do I make them compatible? I have updated the Java on my Mac to 1.8 and when I run java -version or javac -version it confirms this.

What am I missing? (Apart from Java development experience)

Java Solutions


Solution 1 - Java

Select "File" -> "Project Structure".

Under "Project Settings" select "Project"

From there you can select the "Project SDK".

Solution 2 - Java

It means your Java runtime version is 1.6, but your compiler version (javac) is 1.8. To simply solve it, just advance your JVM version to 1.8.

But if you don't want to change the Java runtime version, then do the following steps:

  1. JAVA_HOME= "your jdk v1.8 folder path", to make sure jdk is also v1.8 and use java -version and javac -version again to ensure it
  2. Make sure IntelliJ's compiler mode is set to compliant with v1.6 But i have tried that. it didn't solve my problem.

Solution 3 - Java

If the error comes from an external dependency (maven/gradle), the version you imported requires a newer jdk. (e.g. you imported caffeine 3.0.x which requires java 11 but you are using java 8.)

Solution: downgrade the dependency to the latest version compatible with your jdk.

Java version numbers can be found in Java class file wiki page (byte offset 6-7).

Solution 4 - Java

Have got the same error as in header because of failed attempt to compile my project with java 8 and then reattempting to compile with java 6. Some classes where compiled at the first attempt with 8 and did not recompile with 6. Mixed classes did not compile then. Cleaning project solved the problem. This answer is not strictly relevant to the question, but could be useful for someone.

Solution 5 - Java

If you are using javac to compile, and you get this error, then remove all the .class files

rm *.class     # On Unix-based systems

and recompile.

javac fileName.java

Solution 6 - Java

Generally this kind of error happens when you try run a .class file which is compiled with another version of java. in your case, it is compiled with java 8 (major version -> 52) and you want to run it with java 6 (major version -> 50).

here is a list of major versions of java and SE version: https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.1-200-B.2

to solve the problem, use the same version of the compiled class file, based on your project structure. in Intellij Idea: File | Project Structure | Project | Project SDK

in case of using builder tools like maven, this configuration also should be changed in the corresponding settings. here is an example of how it is done in pom file:

<properties>
    <java.version>11</java.version>
    <maven.compiler.source>${java.version}</maven.compiler.source>
    <maven.compiler.target>${java.version}</maven.compiler.target>
</properties>

Solution 7 - Java

What does the error signifies is that you may have the dependencies that are compiled in Java 11 but you are using Java 8 so, there are two options left you can either migrate to Java 11 or ask the library developer to provide you with a Java 8 build.

Solution 8 - Java

i faced the same problem "Class file has wrong version 52.0, should be 50.0" when running java through ant... all i did was add fork="true" wherever i used the javac task and it worked...

Solution 9 - Java

If the issue in IntelliJ then do this in terminal(not in IntelliJ terminal)- 1.change the java version to appropriate(in my case using jdk 1.4 as issue was class file has wrong version 55.0, should be 52.0)

  1. java -Dspring.profiles.active=test -jar build/libs/<jarname>.jar
    run this

Solution 10 - Java

In your IntelliJ idea find tools.jar replace it with tools.jar from yout JDK8

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjaywaycoView Question on Stackoverflow
Solution 1 - JavaAllan SpreysView Answer on Stackoverflow
Solution 2 - JavaCodeLikeNoonesBusinessView Answer on Stackoverflow
Solution 3 - JavalaffusteView Answer on Stackoverflow
Solution 4 - Javauser3132194View Answer on Stackoverflow
Solution 5 - JavaSadman SakibView Answer on Stackoverflow
Solution 6 - JavaMajid RoustaeiView Answer on Stackoverflow
Solution 7 - JavaN.NeupaneView Answer on Stackoverflow
Solution 8 - JavapraneethView Answer on Stackoverflow
Solution 9 - JavaBUGATTI AJAYView Answer on Stackoverflow
Solution 10 - JavaADAMView Answer on Stackoverflow