Home > Java > javaTutorial > Why Does \'java.lang.UnsupportedClassVersionError\' Occur Despite Matching JRE and Class File Versions?

Why Does \'java.lang.UnsupportedClassVersionError\' Occur Despite Matching JRE and Class File Versions?

Mary-Kate Olsen
Release: 2024-12-02 04:11:11
Original
387 people have browsed it

Why Does

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template