Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UnsupportedClassVersionError due to java 7?

Ok so I just finished an assignment for university and wanted to test my solution on their server and got this exception:

  [java] Exception in thread "main" java.lang.UnsupportedClassVersionError: controller/CloudController : Unsupported major.minor version 52.0
     [java]     at java.lang.ClassLoader.defineClass1(Native Method)
     [java]     at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
     [java]     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
     [java]     at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
     [java]     at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
     [java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
     [java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
     [java]     at java.security.AccessController.doPrivileged(Native Method)
     [java]     at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
     [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
     [java]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
     [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
     [java]     at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
     [java] Java Result: 1

I checked the server and found out they are using Java 7 while I used Java 8 already.

What I then tried was this:

enter image description here

I changed the Project language level to 7, but still this hasn`t solved the problem.

So here is my question, do I really have to download the 1.7 jdk to make this work, because I want to avoid this. The program has to run on the server though, since it is used for the grading and I obviously can`t update the Java version on an university server.

Thanks for any answers in advance.

like image 497
Jakob Abfalter Avatar asked Jan 04 '15 14:01

Jakob Abfalter


People also ask

How do I fix Java Lang UnsupportedClassVersionError in Java?

In order to overcome the UnsupportedClassVersionError, we can either compile our code for an earlier version of Java or run our code on a newer Java version.

What is UnsupportedClassVersionError in Java?

Class UnsupportedClassVersionErrorThrown when the Java Virtual Machine attempts to read a class file and determines that the major and minor version numbers in the file are not supported.

How do I fix Java Lang UnsupportedClassVersionError in Linux?

The solution to the UnsupportedClassVersionError error generally boils down to two options: Run the code with a newer version of Java/JRE, or. Recompile the code with an older Java/JDK compiler.

What version of Java is 55?

This article shows all the major version of the Java class file, for example, Java 17 (major version 61), Java 11 (55), Java 8 (52).


1 Answers

No, you shouldn't need to download JDK 7. This is a project level setting. Here is how I do it on IntelliJ IDEA 14, but I suspect it is the same if you are on 13 or 12.

Go to Settings->Build,Execution,Deployment->Compiler->Java Compiler. Under that tab you should see a Project-wide setting for Project Bytecode Version. Set that to 1.7 and you should be set.

enter image description here

You can also set the per-module settings here if for some reason you have some modules on one version and other modules on another version (but it doesn't sound like you do in this case).

like image 104
Todd Avatar answered Oct 14 '22 00:10

Todd