Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.UnsupportedClassVersionError [duplicate]

When I ran a java program I received this error.. Could you please suggest why do we get this error:

Exception in thread "main" java.lang.UnsupportedClassVersionError:      GenerateInvoice (Unsupported major.minor version 49.0)         at java.lang.ClassLoader.defineClass0(Native Method)         at java.lang.ClassLoader.defineClass(ClassLoader.java:539)         at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)         at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)         at java.net.URLClassLoader.access$100(URLClassLoader.java:55)         at java.net.URLClassLoader$1.run(URLClassLoader.java:194)         at java.security.AccessController.doPrivileged(Native Method)         at java.net.URLClassLoader.findClass(URLClassLoader.java:187)         at java.lang.ClassLoader.loadClass(ClassLoader.java:289)         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)         at java.lang.ClassLoader.loadClass(ClassLoader.java:235)         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302) 
like image 666
user1614043 Avatar asked Oct 07 '12 16:10

user1614043


People also ask

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 does Java Lang UnsupportedClassVersionError mean?

If the JVM identifies that the versions in a class file cannot be supported, it throws an UnsupportedClassVersionError . This error occurs when you compile a program using a higher version of Java and execute it using a JVM of a lower version.

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.


2 Answers

This class was compiled with a JDK more recent than the one used for execution.

The easiest is to install a more recent JRE on the computer where you execute the program. If you think you installed a recent one, check the JAVA_HOME and PATH environment variables.

Version 49 is java 1.5. That means the class was compiled with (or for) a JDK which is yet old. You probably tried to execute the class with JDK 1.4. You really should use one more recent (1.6 or 1.7, see java version history).

like image 86
Denys Séguret Avatar answered Sep 17 '22 12:09

Denys Séguret


Another option is to delete all the classes and rebuild. Having build file is an ideal solution to control whole process like compilation, packaging and deployment. You can also specify source/target versions

like image 22
Satheesh Cheveri Avatar answered Sep 18 '22 12:09

Satheesh Cheveri