Thursday, November 20, 2014

Unsupported major.minor in Java


Exception in thread "main" java.lang.UnsupportedClassVersionError: Concordance : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    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:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: Concordance.  Program will exit.

If your  java program shows above error, then you compiled the file in higher version of java from the version you are executing this jar / war / class.

Ex : Compiled in java 7 and running the program in java 6 (lower version).

How to resolve : Re-compile the program in java 6 to avoid the issues and execute the same. Check your JAVA_HOME added in your PATH  once.

Which is Allowed : You can compile in java 6 and run in java 7 is allowed. Program compiled in lower version  class file can run in higher version. Other-way around is not allowed.
// Below script tag for SyntaxHighLighter