-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.

1
  • Have you tried using the -source and -target flags to specify the bytecode version you want? E.g. -target 6. Commented Jan 17, 2013 at 18:52

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

3 Comments

sorry, but how to do it? cos im not very familiar with it
Install the latest JDK (1.7u11, at the moment) from here: oracle.com/technetwork/java/javase/downloads/index.html
Alternatively, in NB, right click your project, choose properties, and change target/binary to JDK-6
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.

2 Comments

what is the solution? how to change it? i have 3 main classes
Make sure Java version on Mac is same as Java version on your windows.
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.