Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.UnsupportedClassVersionError: Bad version number in .class file

I'm having this error in eclipes java.lang.UnsupportedClassVersionError: Bad version number in .class file.

When I run javac -version it prints

javac 1.5.0_28

Within eclipes if I right click, properties->java compiler it says I'm using 1.5 and if I then go to java build path, I have JRE System Library [JVM 1.5.0 (MacOS X Default)] in there.

Why am i getting this error and how do I fix it?

EDITS

java -version prints

java version "1.5.0_28"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_28-b04-382-9M3326)
Java HotSpot(TM) Client VM (build 1.5.0_28-157, mixed mode, sharing)

The other libraries in my application is the libgdx library.

The full error is

Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:676)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:317)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:280)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:375)
like image 325
dotty Avatar asked Jun 27 '11 13:06

dotty


People also ask

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.

How do you solve UnsupportedClassVersionError?

The solution to the UnsupportedClassVersionError error generally boils down to two options: Run the code with a newer version of Java/JRE, or. Recompile the code with an older Java/JDK compiler.

What is UnsupportedClassVersionError?

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.

What version of Java is 55?

This article shows all the major version of the Java class file, for example, Java 17 (major version 61), Java 11 (55), Java 8 (52).


2 Answers

You get this error when you try to run a class that was compiled for a Java version newer than what you have; for example, if you try to use a class that was compiled for Java 6 or newer on a Java 5 JVM.

It doesn't necessarily have to be your own class; you might be using some library that was built for Java 6 or newer.

Are you using specific libraries (JAR files)? Check if these are compatible with Java 5 or not. Or upgrade your Java version to Java 6.

like image 135
Jesper Avatar answered Oct 07 '22 00:10

Jesper


My guess is that you are using 3rd party libraries built with Java 1.6.

By the way is there any reason you are using Java 1.5? Java 1.6 is out for long and Java 1.5 will no longer be supported real soon (if not already).

like image 41
gabuzo Avatar answered Oct 07 '22 02:10

gabuzo