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:
PATH as C:\Program Files\Java\jdk-13 JAVA_HOME as: C:\Program Files\Java\jdk-13 JRE_HOME as: C:\Program Files\Java\jre1.8.0_221
I've set the path, 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)
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 thebin
subdirectory for the latest JDK version at the top of thePATH
list.java.exe
executable is inC:\Program Files\Java\jdk-13\bin
directory, so that is what you need to have inPATH
.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 inPATH
above or instead of Java 8. On Windows you may haveC:\Program Files (x86)\Common Files\Oracle\Java\javapath
added toPATH
automatically which points to Java 8 now: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 Restart as administrator first to be able to edit the System variables (see the button on the top right of the system variables column).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:
I also removed the path as suggested by @CrazyCoder
i am facing same problem when i installed jre by Oracles and solved this problem after my research.
i am moved the environment path
C:\Program Files (x86)\Common Files\Oracle\Java\javapath
Bellow ofH:\Program Files\Java\jdk-13.0.1\bin
Like this:-
OR