nobism
nobism

Reputation: 1947

Has been compiled by a more recent version of the Java Runtime (class file version 57.0)

I get this problem using IntelliJ. But I have the newest version of everything newly installed on my system.

... has been compiled by a more recent version of the Java Runtime
(class file version 57.0), this version of the Java Runtime only
recognizes class file versions up to 52.0

I've set:

I've set the path, and I tried to find a change in the Project structure.

Complete error message

H:\087-JAVA\HelloWorld\src>java com.codewithmosh.Main
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/codewithmosh/Main has been compiled by a more recent version of the Java Runtime (class file version 57.0), this version of the Java Runtime only recognizes class file versions up to 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

Upvotes: 193

Views: 740704

Answers (18)

JJD
JJD

Reputation: 51874

If you try to run a main() function in IntelliJ / Android Studio and get the following error:

/usr/lib/jvm/java-11-openjdk-amd64/bin/java ... Error: LinkageError occurred while loading main class ExampleKt java.lang.UnsupportedClassVersionError: ExampleKt has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0

Then manually change the JRE version in the associated the run configuration. Select Edit Configurations... from the dropdown menu on top of your IDE next to the green run button.

JRE setting

You can ease your life if you set the JRE version in the Edit configuration templates... so it will be applied to all future run configurations that you create.

Related

Upvotes: 0

Qadir Khan
Qadir Khan

Reputation: 305

In case of android studio, I fixed this issue by simply updated the Gradle Jdk.

1: At left side of android studio click on Gradle tab --> next click on setting icon --> select Gradle settings

enter image description here

2: Now you will see the Gradle JDK and here you can update it and it will solve the problem in my case I updated to Jbr-17

enter image description here

Upvotes: 9

Hani
Hani

Reputation: 1313

The easiest solution is to change the Java version in your IDE. In Intellij, go to File --> Project Structure and change the Project SDK to the one that is supported by your Java Runtime (in your case it's 52 which corresponds to version 8 or less). Here's a table that shows the mapping between Java SE Version and Major Version:

Java SE Major version
1.0.2 45
1.1 45
1.2 46
1.3 47
1.4 48
5.0 49
6 50
7 51
8 52
9 53
10 54
11 55
12 56
13 57
14 58
15 59
16 60
17 61
18 62
19 63
20 64
21 65

The table is taken from: https://docs.oracle.com/javase/specs/jvms/se21/html/jvms-4.html

Upvotes: 101

veet
veet

Reputation: 59

For IntelliJ IDEA 2021.2.3

After updating Module SDK to openjdk-17, it worked for me. openjdk version "1.8.0_272"

Menu FileProject StructureModules (Project Settings)Module SDK (select openjdk-17). If openjdk-17 is not there, then from the dropdown, select Add SDKDownload JDK and add openjdk-17.

Upvotes: 2

Vladi
Vladi

Reputation: 1990

How I solved it in Eclipse:

  1. go to the properties of the project

    Enter image description here

  2. go to Java compiler

    Enter image description here

  3. change in the Compiler complicated level to the Java version that my project work with (Java 11 in my project). You can see that it your Java that you work when the last message disappear

  4. Apply

    Enter image description here

Upvotes: 10

muilpp
muilpp

Reputation: 1353

The problem is that you compiled the code with Java 13 (class file 57), and the java runtime is set to Java 8 (class file 52).

Assuming you have the JRE 13 installed in your local system, you could change your runtime from 52 to 57. That you can do with the plugin Choose Runtime. To install it go to File/Settings/Plugins.

Enter image description here

Once installed go to Help/Find Action, type "runtime" and select the JRE 13 from the dropdown menu.

Enter image description here

Upvotes: 3

CrazyCoder
CrazyCoder

Reputation: 402235

You need to double check the PATH environment setting. C:\Program Files\Java\jdk-13 you currently have there is not correct. Please make sure you have the bin subdirectory for the latest JDK version at the top of the PATH list.

java.exe executable is in C:\Program Files\Java\jdk-13\bin directory, so that is what you need to have in PATH.

Use this tool to quickly verify or edit the environment variables on Windows. It allows to reorder PATH entries. It will also highlight invalid paths in red.

If you want your code to run on lower JDK versions as well, change the target bytecode version in the IDE. See this answer for the relevant screenshots.

See also this answer for the Java class file versions. What happens is that you build the code with Java 13 and 13 language level bytecode (target) and try to run it with Java 8 which is the first (default) Java version according to the PATH variable configuration.

The solution is to have Java 13 bin directory in PATH or above instead of Java 8. On Windows you may have C:\Program Files (x86)\Common Files\Oracle\Java\javapath added to PATH automatically which points to Java 8 now:

javapath

If it's the case, remove the highlighted part from PATH and then logout/login or reboot for the changes to have effect. You need to Restrart as administrator first to be able to edit the System variables (see the button on the top right of the system variables column).

enter image description here

Upvotes: 68

Sergey
Sergey

Reputation: 344

I had this problem with Android Studio.
I fixed it by updating Gradle to 6.5, and Gradle plugin to 4.11.

Upvotes: 0

Jan Seevers
Jan Seevers

Reputation: 788

I got the problem after an upgrade to java 17. Then I was running the older Run/Debug configuration and needed to update the path to the JDK

enter image description here

Upvotes: 5

ibra
ibra

Reputation: 1304

  1. File
  2. Settings
  3. Build, Execution, Deployment:
  4. Compiler
  5. Java Compiler
  6. in Project bytecode version choose 8

Intellij Project bytecode version 8

Upvotes: 4

baptx
baptx

Reputation: 3906

On Linux, I got this error when trying to run SoapUI. Installing the latest OpenJDK JRE package fixed the issue, for example with Ubuntu: sudo apt install openjdk-17-jre.

I found this question on a search engine, so maybe it will help other people.

Upvotes: 3

Singh Arun
Singh Arun

Reputation: 370

For eclipse IDE,

Please follow the below steps -

  1. Right Click on "Project" -> "properties"
  2. Click on "Java Compiler"
  3. Check "Enable Project Specific Setting"
  4. Correct the "compiler compilation level" ( ref pic is attached )
  5. If needed, verify and correct java build path for the project as well.

Eclipse Project Properties Window

Upvotes: 5

Ajay Kr Choudhary
Ajay Kr Choudhary

Reputation: 1372

I have run into this issue When I recently upgraded my IntelliJ version to 2020.3. I had to disable a plugin to solve this issue. The name of the plugin is Thrift Support.

Steps to disable the plugin is following:

  1. Open the Preferences of IntelliJ. You can do so by clicking on Command + , in mac.
  2. Navigate to plugins.
  3. Search for the Thrift Support plugin in the search window. Click on the tick box icon to deselect it.
  4. Click on the Apply icon.
  5. See this image for reference Disable_Thrift_support_plugin

For more detail please refer to this link java.lang.UnsupportedClassVersionError 2020.3 version intellij. I found this comment in the above link which has worked for me.

bin zhao commented 31 Dec 2020 08:00 @Lejia Chen @Tobias Schulmann Workflow My IDEA3.X didn't installed Erlang plugin, I disabled Thrift Support 1.4.0 and it worked. Both IDEA 3.0 and 3.1 have the same problem.

Upvotes: 2

Thomas Gotwig
Thomas Gotwig

Reputation: 4469

For me it worked after removing the target folder 🗑

Upvotes: 5

Martin Zeitler
Martin Zeitler

Reputation: 76769

This is a setting in IntelliJ IDEA ($JAVA_HOME and language level were set to 1.8):

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

Select eg. Project SDK (corretto-1.8) (or any other compatible version).

Then delete the build directory and restart the IDE.

Upvotes: 50

S Kumar
S Kumar

Reputation: 258

I was facing same problem when I installed JRE by Oracle and solved this problem after my research.

I moved the environment path C:\Program Files (x86)\Common Files\Oracle\Java\javapath below H:\Program Files\Java\jdk-13.0.1\bin

Like this:

Path

H:\Program Files\Java\jdk-13.0.1\bin
C:\Program Files (x86)\Common Files\Oracle\Java\javapath

OR

Path

%JAVA_HOME%
%JRE_HOME%

Upvotes: 7

Memin
Memin

Reputation: 4090

I had similar problem with IntelliJ when tried to run some Groovy scripts. Here is how I solved it.

Go to "Project Structure"-> "Project" -> "Project language level" and select "SDK default". This should use the same SDK for all project modules.

Upvotes: 19

Karan
Karan

Reputation: 856

I also encountered similar problem which is asked here. The issue was that some applications come with their own JRE and sometimes the installed JDK appears at lower priority level in environment path. Now there are two options:

  1. Uninstall the other application which has their own JDK/JRE.
  2. Sometimes it is not possible to remove the other application, which was my case. So I moved JDk installed by me to higher priority level in environment path.

enter image description here

I also removed the path as suggested by @CrazyCoder

Upvotes: 17

Related Questions