Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Supporting Your Unsupported Class Version Error [Code Snippet]

DZone's Guide to

Supporting Your Unsupported Class Version Error [Code Snippet]

Here's a quick fix if you're running into the UnsupportedClassVersionError. It could be as simple as making sure your PATH variable is playing nicely with JAVA_Home.

· Java Zone ·
Free Resource

Get the Edge with a Professional Java IDE. 30-day free trial.

This article covers how to fix Java errors akin to UnsupportedClassVersionError. Please feel free to comment/suggest if I missed something.

How to Reproduce the Error

  • Set JAVA_HOME with one version of Java. Include a “bin” of different Java versions in the PATH variable.
  • Compile the class, for example HelloWorld.java, with “javac”.
  • Start the JVM with following class: “java HelloWorld”.

With the steps above, you might see an error like:

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.

Basically, you want to make sure that same version is set as JAVA_HOME as it's included in the PATH variable (%JAVA_HOME%/bin). That should fix your problem!

Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.

Topics:
java ,error ,unsupportedclassversionerror

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}