This article represents tips on how to fix Java error such as UnsupportedClassVersionError. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos.
How to Reproduce the Error?
- Set the JAVA_HOME with one version of Java. And, include “bin” of different Java version in PATH variable.
- Compile the class, say, HelloWorld.java with “javac” command
- Start the JVM with following class: “java HelloWorld”
With above, you could see error such as following:
java.lang.UnsupportedClassVersionError: HelloWorld : Unsupported major.minor ver sion 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)
I set the JAVA_HOME for jdk 8.* and set the jdk7.* in PATH.
How to Fix the java.lang.UnsupportedClassVersionError?
Make sure that same version is set as JAVA_HOME as included in PATH variable (%JAVA_HOME%/bin)
Latest posts by Ajitesh Kumar (see all)
- When to use Deep Learning vs Machine Learning Models? - January 17, 2021
- Most Common Types of Machine Learning Problems - January 14, 2021
- Historical Dates & Timeline for Deep Learning - January 10, 2021