- Instant help with your Java coding problems

Solving the Error: unsupported class file major version

Question:
How to solve the unsupported class file major version error?
Answer:
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="GradleMigrationSettings" migrationVersion="1" />
  <component name="GradleSettings">
    <option name="linkedExternalProjectsSettings">
      <GradleProjectSettings>
        <option name="delegatedBuild" value="false" />
        <option name="testRunner" value="PLATFORM" />
        <option name="distributionType" value="LOCAL" />
        <option name="externalProjectPath" value="$PROJECT_DIR$" />
        <option name="gradleHome" value="C:/Program Files/gradle/gradle-7.2" />
        <option name="gradleJvm" value="17" />
        <option name="modules">
          <set>
            <option value="$PROJECT_DIR$" />
          </set>
        </option>
      </GradleProjectSettings>
    </option>
  </component>
</project>
Description:

In Java if you try to load something compiled for newer version of java in an older version runtime you'll get the error: Unsupported class file major version or Incompatible class version, got X, expected Y.

For example, if you try to load something compiled for java 16 in a java 14 runtime you'll get the error: Incompatible class version, got 60, expected 58 or the error: Unsupported class file major version 60

A typical use case using IntelliJ or Android Studio IDE with gradle build tool. If you have a project that uses JDK 14 with gradle 6.3 and you upgrade the JDK to version 16 then you get the error Unsupported class file major version 60 because gradle 6.3 is not compatible with Java 16. So the root cause is independent from your IDE. It can be also Eclipse, Visual Studio Code or any other.

The solution is to use comaptible JDK and gradle versions. See Java major numbers and gradle compatibility matrix.

In IntelliJ also check the following settings:

File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle -> Gradle JVM

 

 

 

Share "How to solve the unsupported class file major version error?"
Tags:
unsupported class file major version, 62, 61, 60, 59, 58, 57, 56, 55, intellij, gradle, maven, android studio
Technical term:
unsupported class file major version, intellij, gradle, android studio, maven, vscode