Class file has wrong version 52.0, should be 50.0
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)
Solution 1:
Select "File" -> "Project Structure".
Under "Project Settings" select "Project"
From there you can select the "Project SDK".
Solution 2:
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:
-
JAVA_HOME= "your jdk v1.8 folder path"
, to make sure jdk is also v1.8 and usejava -version
andjavac -version
again to ensure it - 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:
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 4:
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).