-4

Possible Duplicate:
Exception in thread “main” java.lang.UnsupportedClassVersionError: a (Unsupported major.minor version 51.0)

My Java program which I run on Mac & Windows is not working. Instead I get this error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: menus/Main_Screen : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    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)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

Does anyone know how to fix this? Thanks.

Community
  • 1
  • 1
Ameera Rio
  • 1
  • 1
  • 1
  • Have you tried using the `-source` and `-target` flags to specify the bytecode version you want? E.g. `-target 6`. – Mike Samuel Jan 17 '13 at 18:52

3 Answers3

3

Class version 51.0 is generated by Java 7.

You're trying to run with an earlier version, probably Java 6. You need to call the Java 7 version of the java command.

The version used to run NetBeans is set in NetBeans/etc/netbeans.conf.
The version used to build and run a project is set by the project properties.
You can tell NetBeans about a new Java version through the Tools > Java Platforms

Devon_C_Miller
  • 16,248
  • 3
  • 45
  • 71
0
Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(

It seems your java runtime version is different (lower) version from compile time version.

kosa
  • 65,990
  • 13
  • 130
  • 167
0

The general rule is this.

If take a *.class compiled by a version of Java EARLIER than the JRE, it should work in that JRE. Because the later JRE is supposed to "know" previous versions of format.

If take a *.class compiled by a version of Java LATER than the JRE, it should not work in that JRE. Because the earlier JRE is not supposed to know the future versions of format.


In your case the code is simply compiled by the version of Java issued after the version of the JRE.

Alex Kreutznaer
  • 1,170
  • 8
  • 18