1

Possible Duplicate:
unsupported major .minor version 51.0

I made a simple java program

class MyProg{    
  public static void main(String args[]){    
  System.out.println("Hello World");      }
}

but when I try run it this happens

wil@wil-ThinkPad-T42:~/Dropbox/java$ javac -g MyProg.java
wil@wil-ThinkPad-T42:~/Dropbox/java$ java MyProg
Exception in thread "main" java.lang.UnsupportedClassVersionError: MyProg : 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: MyProg. Program will exit.

What is wrong with the program?

Community
  • 1
  • 1
wil
  • 171
  • 3

3 Answers3

1

Your Java toolchain seems to be wrong. The program looks good to me. I think this helps:

http://notroswell.com/technical-articles/java-version-mismatch/

eactor
  • 862
  • 3
  • 14
  • 34
0

You're executing your class with a java virtual machine older than the compiler you used to compile the class.

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
0

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

The version number shown describes the version of the JRE that the class file is compatible with.

J2SE 7 = 51,
J2SE 6.0 = 50,
J2SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841