Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is java.lang.UnsupportedClassVersionError?

what is java.lang.UnsupportedClassVersionError ?

I read from the doc :Thrown when the Java Virtual Machine attempts to read a class file and determines that the major and minor version numbers in the file are not supported , but couldn't understand what does that mean.

What are the major and minor versions in the file ?

I launched an application in someone else machine when the following exception was thrown :

Exception in thread "main" java.lang.UnsupportedClassVersionError: client (Unsupported major.minor version 51.0)
   at java.lang.ClassLoader.defineClass0(Native Method)
   at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
   at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
   at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
   at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
   at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
   at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)

though it worked fine on my machine.

like image 677
Suhail Gupta Avatar asked Dec 22 '11 14:12

Suhail Gupta


People also ask

What is UnsupportedClassVersionError in Java?

Class UnsupportedClassVersionErrorThrown when the Java Virtual Machine attempts to read a class file and determines that the major and minor version numbers in the file are not supported.

How do I fix Java Lang UnsupportedClassVersionError in Java?

In order to overcome the UnsupportedClassVersionError, we can either compile our code for an earlier version of Java or run our code on a newer Java version.

When my class encounter UnsupportedClassVersionError which options would resolve this issue?

1) If you encounter UnSupportedClassVersionError, check the JRE version you are using to run program and switch to higher version for quick solution.

What version of Java is 61?

Java 17 uses major version 61.


2 Answers

Different versions of the JDK compiler generate different class versions. For instance, Java 1.4 generates 48.0, 1.5 generates 49.0 and 1.6 50.0.

A JVM is generally able to load classes from JVMs "lesser" than itself but never greater. You are probably trying to use a class compiled for 1.6 on a 1.5 JVM, or the like.

A good tool for finding class versions is bcel if you are interested. In particular, it has a nice set of ant tasks.

like image 166
fge Avatar answered Oct 05 '22 16:10

fge


That means your compiler version is more recent than the jvm version where you are trying to run the classes. Either downgrade your machine's java compiler or upgrade the other machine's runtime jvm.

like image 44
d-live Avatar answered Oct 05 '22 17:10

d-live