java.lang.UnsupportedClassVersionError: Bad version number in .class file?
I've learned that error messages like this are usually right. When it couldn't POSSIBLY (in your mind) be what the error being reported says, you go hunting for a problem in another area...only to find out hours later that the original error message was indeed right.
Since you're using Eclipse, I think Thilo has it right The most likely reason you are getting this message is because one of your projects is compiling 1.6 classes. It doesn't matter if you only have a 1.5 JRE on the system, because Eclipse has its own compiler (not javac), and only needs a 1.5 JRE to compile 1.6 classes.
It may be weird, and a setting needs to be unchecked to allow this, but I just managed to do it.
For the project in question, check the Project Properties (usually Alt+Enter), Java Compiler section. Here's an image of a project configured to compile 1.6, but with only a 1.5 JRE.
java.lang.UnsupportedClassVersionError: Bad version number in .class file
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.
How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
The version number shown describes the version of the JRE the class file is compatible with.
The reported major numbers are:
Java SE 18 = 62,
Java SE 17 = 61,
Java SE 16 = 60,
Java SE 15 = 59,
Java SE 14 = 58,
Java SE 13 = 57,
Java SE 12 = 56,
Java SE 11 = 55,
Java SE 10 = 54,
Java SE 9 = 53,
Java SE 8 = 52,
Java SE 7 = 51,
Java SE 6.0 = 50,
Java SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45
(Source: Wikipedia)
To fix the actual problem you should try to either run the Java code with a newer version of Java JRE or specify the target parameter to the Java compiler to instruct the compiler to create code compatible with earlier Java versions.
For example, in order to generate class files compatible with Java 1.4, use the following command line:
javac -target 1.4 HelloWorld.java
With newer versions of the Java compiler you are likely to get a warning about the bootstrap class path not being set. More information about this error is available in a blog post New javac warning for setting an older source without bootclasspath.
Related Topics
How to Send Large Messages with Kafka (Over 15Mb)
Generate/Get Xpath from Xml Node Java
Why Does Writeobject Throw Java.Io.Notserializableexception and How to Fix It
What Is an Outofmemoryerror and How to Debug and Fix It
Java: How to Start a Standalone Application from the Current One When Both Are in the Same Package
How to Create a Rest Client for Java
How to Get the File Extension of a File in Java
What Is @Modelattribute in Spring MVC
How to Tell If I'm Running in 64-Bit Jvm or 32-Bit Jvm (From Within a Program)
Java Class That Implements Map and Keeps Insertion Order
Why Can Outer Java Classes Access Inner Class Private Members
Reading a List from Properties File and Load with Spring Annotation @Value
Returning from a Finally Block in Java
How to Override Class Variables in Java
How to Gracefully Handle the Sigkill Signal in Java
How to Find Files That Match a Wildcard String in Java