Resolving "java.lang.UnsupportedClassVersionError: Bad Version Number in .class File"
Despite receiving an error message suggesting a version mismatch, further investigation reveals that the JRE and compiled classes are both running on the same version. This leads to the question: can an internal class issue trigger the error?
Answer:
The answer lies within the intricacies of Eclipse's Java development environment. Contrary to the apparent constraint of only using a 1.5 JRE, Eclipse possesses its own compiler capable of creating 1.6 classes. This can occur even in the absence of an explicitly defined 1.6 JRE.
Solution:
To resolve this issue, check the project properties within Eclipse (Alt Enter). Navigate to the Java Compiler section and ensure that the project is not erroneously configured to compile 1.6 classes while using a 1.5 JRE.
Example:
If the project's Java Compiler settings resemble those shown in the following image, it is compiling 1.6 classes with a 1.5 JRE, leading to the error.
[Image of Eclipse project configured for Java 6 compilation with a Java 5 JRE]
The above is the detailed content of Why Does \'java.lang.UnsupportedClassVersionError\' Occur Despite Matching JRE and Class File Versions?. For more information, please follow other related articles on the PHP Chinese website!