Tuesday, May 5, 2015

Error in Running Java Project in Eclipse

I got the below error in my eclipse. The reason is I have selected a compiler and run time (jre) in two different versions.


-------------------------------------------------------------------------------
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/concurrency/RunnableWithLamda : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(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.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 sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
----------------------------------------------------------------------------------------------


To solve the above error.
First go to
select the project --> right cick
go to "Properties" --> select java compiler .... let's say we have selected 1.8
Then   in below you will see a message that JRE is set to some version eg:1.7
So change it to 1.8 or higher version than the compiler version

In my case I have given 1.8 version for compiler and 1.7 for the JRE.

Important : UnsupportedClassVersionError
when you get the above mentioned error, always look for the JRE version you have selected.
mostly this error may come due to JRE version lower being lower than the compiler version.