0

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.

Ontonator
  • 319
  • 3
  • 17
  • Your Eclipse may be running on a older installed Java version. Do you have many jdk installed on your system? Check your eclipse.ini to see what -vm parameter it's being used. – watery Jan 06 '14 at 00:44
  • Have you tried going to project>CLEAN , and rebuilding everything from scratch. Maybe the files in BIN folder are from the other PC compiled with other version JDK. Also have a look at http://stackoverflow.com/questions/7237536/exception-in-thread-main-java-lang-unsupportedclassversionerror-a-unsupporte as it may be your path. – Menelaos Jan 06 '14 at 00:45
  • There is no -vm parameter there. Here is the contents of the file: [eclipse.ini](http://pastebin.com/NbHmrqj7). – Ontonator Jan 08 '14 at 23:22

1 Answers1

0

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.

Community
  • 1
  • 1
Menelaos
  • 23,508
  • 18
  • 90
  • 155
  • I tried rebuilding the class files, but that didn't seem to have any effect. Also, I have selected "Java SE 7 [1.7.0_45]" as my default JRE, and I am compiling with a compliance level of 1.7. I have checked to make sure that the path to the JRE is correct as well. The library for the project is the same as the default one. Could it be anything to with the fact that Mac OS X insists on using Java 6? I wouldn't have thought that that would matter, because Eclipse allows one to specify a specific JRE system library. – Ontonator Jan 06 '14 at 01:48
  • Can you set the compliance level to 1.6 and see what happens? – Menelaos Jan 06 '14 at 08:58
  • I get this error message: Exception in thread "main" java.lang.Error: Unresolved compilation problem: Multi-catch parameters are not allowed for source level below 1.7 at gameLogics.Game.(Game.java:126) at gameLogics.Game.main(Game.java:149) – Ontonator Jan 06 '14 at 22:43
  • See: http://docs.oracle.com/javase/7/docs/technotes/guides/language/catch-multiple.html . If your switching to 1.6 it means 1.7 features not supported. You need to get rid of the multi-catch that uses "|". Also, I think the problem is that mac OS x is using java 6. Can you install java 7? – Menelaos Jan 07 '14 at 00:24
  • I have the Java 7 JDK, and I have tried installing the JRE, although it didn't do much good. If I remove Java 6, I can't launch Eclipse. I don't understand how this could be the problem though, because it works perfectly on other computer, and it also works fine if I export it as a runnable jar file. If I remove the multi-catches, it does work with a compliance level of 1.6, but I don't want to be limited by it. – Ontonator Jan 07 '14 at 01:05