Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception in thread "main" java.lang.UnsupportedClassVersionError: a (Unsupported major.minor version 51.0) [duplicate]

Possible Duplicate:
unsupported major .minor version 51.0

I installed JDK7, a simple hello word program gets compile but when I run this I got following exception.

Exception in thread "main" java.lang.UnsupportedClassVersionError: a (Unsupported major.minor version 51.0)     at java.lang.ClassLoader.defineClass0(Native Method)     at java.lang.ClassLoader.defineClass(Unknown Source)     at java.security.SecureClassLoader.defineClass(Unknown Source)     at java.net.URLClassLoader.defineClass(Unknown Source)     at java.net.URLClassLoader.access$100(Unknown Source)     at java.net.URLClassLoader$1.run(Unknown Source)     at java.security.AccessController.doPrivileged(Native Method)     at java.net.URLClassLoader.findClass(Unknown Source)     at java.lang.ClassLoader.loadClass(Unknown Source)     at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)     at java.lang.ClassLoader.loadClass(Unknown Source)     at java.lang.ClassLoader.loadClassInternal(Unknown Source) 

I checked java -version on command prompt, it shows Java version 1.4.2_03 but when I tried to install new java version from java.com it says that I'm having recommended Java 7 version.

like image 489
Adnan Avatar asked Aug 30 '11 00:08

Adnan


People also ask

How do I fix Java Lang UnsupportedClassVersionError unsupported major minor version?

There are two ways to solve this problem, first make sure you run your Java program in the same or higher version of JRE, on which it has compiled, and second use the cross-compilation option to create a class file compatible to a lower JRE.

How do I fix Java Lang UnsupportedClassVersionError in Java?

UnsupportedClassVersionError happens because of a higher JDK during compile time and lower JDK during runtime. How can i make above change? Project -> Properties -> Java Compiler Enable project specific settings. Then select Compiler Compliance Level to 1.7, 1.6 or 1.5, build and test your app.

What is UnsupportedClassVersionError in Java?

Class UnsupportedClassVersionErrorThrown when the Java Virtual Machine attempts to read a class file and determines that the major and minor version numbers in the file are not supported.


1 Answers

Try sudo update-alternatives --config java from the command line to set the version of the JRE you want to use. This should fix it.

like image 121
johnzachary Avatar answered Sep 20 '22 17:09

johnzachary