29

I'm not a programmer but I couldn't find any answer on this website. I'm trying to run a game on linux ubuntu with Java Open JDK but nothing happen. I tried to run it with the prompt command and it said this:

leops95@leops95-SATELLITE-C660:~$ '/home/leops95/Bureau/Minecraft.jar' Exception in thread "main" java.lang.UnsupportedClassVersionError: net/kc/main/Main :

Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)

Could not find the main class: net.kc.main.Main. Program will exit.

I think there is something wrong with the version of Java, right ?

Tom
  • 16,842
  • 17
  • 45
  • 54
user3120480
  • 299
  • 1
  • 3
  • 3
  • You need Java 7, and I think you need the Oracle one: http://askubuntu.com/questions/56104/how-can-i-install-sun-oracles-proprietary-java-6-7-jre-or-jdk – Samuel Edwin Ward Dec 19 '13 at 19:36
  • 1
    This is not as such a duplicate, since the fix on Ubuntu is _different_ fron the windows fix. Please reconsider! – Thorbjørn Ravn Andersen Dec 19 '13 at 21:25
  • @jpaugh The language tag has nothing to do with this question and trying to make it less of a duplicate by adding unrelated tags is ... pointless. – Tom Nov 29 '15 at 03:57

2 Answers2

31

This is because of a higher JDK during compile time and lower JDK during runtime. So you just need to update your JDK version, possible to JDK 7

You may also check Unsupported major.minor version 51.0

Community
  • 1
  • 1
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
  • 6
    @user3120480:- The same link gave the hint:- `On Eclipse, I just went to Preferences > Java > Compiler and then set "Compiler compliance level" to 1.6.` – Rahul Tripathi Dec 19 '13 at 19:39
  • I don't have "Eclipse", that's the problem... Must I download it ? – user3120480 Dec 19 '13 at 19:43
  • 1
    @user3120480:- No you dont need to download eclipse if you dont have then you may try with `apt-get install openjdk-7-jdk` as suggested by Andersen – Rahul Tripathi Dec 19 '13 at 19:45
  • I unistalled openjdk-6 and wrote the command apt-get install openjdk-7-jdk but the result is the same – user3120480 Dec 19 '13 at 19:54
  • I am facing this error.. Even though in my case i ran the update-alternatives --config java and update-alternatives --config javac and selected Java 1.7 and javac 1.7. Any idea? – Ankur Bhatia May 09 '16 at 10:31
10

The Java runtime you try to execute your program with is an earlier version than Java 7 which was the target you compile your program for.

For Ubuntu use

apt-get install openjdk-7-jdk

to get Java 7 as default. You may have to uninstall openjdk-6 first.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347