-1

I use jdk1.8.0_221 to compile (in IntelliJ). There is javac 1.8.0_191 on my server.

Any ideas why I still receive an error, like that:

Exception in thread "main" java.lang.UnsupportedClassVersionError: pp/PP 
has been compiled by a more recent version of the Java Runtime (class file 
version 55.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(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at pp.WebServer$.main(WebServer.scala:16)
at pp.WebServer.main(WebServer.scala)

P.S. Working solution has nothing to do with Java versions. See below.

P.S.1 To those, who mark question as duplicate. Other questions are on cases when Java versions are different. In my case I got an error, when versions are equal and solved it doing nothing with jdk. Absolutely different case. You should be more attentive.

14
  • 4
    Exactly how did you compile pp/PP? And have you ever installed Java 11? Because your error says you have. Commented Aug 28, 2019 at 2:56
  • 3
    The Java 8 compiler won't produce a class file with a version of 55.0. Commented Aug 28, 2019 at 3:33
  • 1
    On a side note: It is better to rely on a build tool like Maven or Gradle to compile. Relying on your IDE is not such a good idea as it makes it harder to have reproducible builds. Commented Aug 28, 2019 at 11:25
  • 3
    Really, the only way you can get this error is if you try to use a class that was compiled with JDK 11, on a Java 8 runtime. You say you have "checked and rechecked" and you are convinced it is not a compiler case - but I'm afraid you are wrong. The compiler and Java runtime don't lie.
    – Jesper
    Commented Aug 28, 2019 at 11:31
  • 1
    That's your sdk for development purposes, it won't do a single thing to fix how you're compiling (if using IntelliJ to build and not a build system) and it won't even affect the output code. You need to set this in a couple locations, but mostly it's setting the project bytecode target and the project language level
    – Rogue
    Commented Aug 28, 2019 at 12:05

1 Answer 1

-1

To fix such problem in IntelliJ do: File->Project Structure->Project Settings->Modules

In the very bottom "Dependencies storage format" select -> Eclipse(.classpath) -> Apply

Error gone.

Not the answer you're looking for? Browse other questions tagged or ask your own question.