Question

When I try to run a Java program in Eclipse on one of my computers, I get this error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: gameLogics/Game : Unsupported major.minor version 51.0

at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

I searched the internet and found multiple solutions, but they all just said that I was trying to run it with an older version of Java than I compiled it with. The only solution was to re-download Java or set the compliance level of Eclipse to 1.6, neither of which worked for me. (The compliance level one did not work because I used some features only available in Java 7. I did use it before and it worked, but I required some features from Java 7.)

Curiously, the project works perfectly on my other computer using exactly the same files, including preference files and application data. It also works if I export it on either computer, so only Eclipse's run feature seems to be broken.

I have not provided any code because there is no single relevant part, so I would have to upload all of my code.

Is there any solution for this that is not one of the ones that I mentioned earlier in this post?

EDIT: Both of my computers are Macs if it is important.

Was it helpful?

Solution

Two options:

  1. It's a path issue: See: Exception in thread "main" java.lang.UnsupportedClassVersionError: a (Unsupported major.minor version 51.0)
  2. You need to rebuild the class files.

Have you tried rebuilding your project? I would suggect to CLEAN and REBUILD. If this doesn't work, go to the bin folder and delete everything inside. I suspect that eclipse is not cleaning the old .class files from the other computer.

If this doesn't work see the link as it may be a path issue. As another post says:

java.lang.UnsupportedClassVersionError happens because of a higher JDK during compile time and lower JDK during runtime.

So, you need to check your settings and paths. Most likely you may be compiling and running with different JDK versions/levels.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top