javacodex.com
Java Examples
Java Examples
memu home questions

Why do I get an "Unsupported major.minor version" when I run a java program?

You will get this type of exception when you run the program with a lower version of the JDK then it was compiled with.

The example program was compiled with JDK 1.7 and is run with JDK 1.6

Example:

$ java HelloWorld 
Exception in thread "main" java.lang.UnsupportedClassVersionError: 
  HelloWorld : 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)
Could not find the main class: HelloWorld.  Program will exit.


$ java -version
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b05)
Java HotSpot(TM) Client VM (build 20.6-b01, mixed mode)

Reported major numbers:

JDK 1.8 = 52
JDK 1.7 = 51
JDK 1.6 = 50
JDK 1.5 = 49
JDK 1.4 = 48
JDK 1.3 = 47
JDK 1.2 = 46
JDK 1.1 = 45

Questions answered by this page:

How to fix: Unsupported major.minor version 51.0 error? Runtime Java error: (Unsupported major.minor version 49.0)




Contact: javacodex@yahoo.com