The type java.util.Map$Entry cannot be resolved. 问题解决

本文介绍了在使用Eclipse搭建SpringMVC环境时遇到的关于Map.Entry无法解析的问题及详细解决方案。问题源于IDE与JDK版本不匹配导致的类文件解析错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天使用Eclipse搭建SpringMVC环境的时候,遇到一个Error:

An error occurred at line: 1 in the generated java file
The type java.util.Map$Entry cannot be resolved. It is indirectly referenced from required .class files

Stacktrace:
    at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
    at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)

本地环境:

java version “1.8.0_45”

apache-tomcat-6.0.35

Eclipse Java EE IDE for Web Developers. Version: Luna Service Release 2 (4.4.2)

解决办法:

国内网站简单查了下,全说降低JDK版本。没明白根本原因,然后在StackOverFlow找到解答。下面是链接。

StackOverFlow
里面这么说:

When using JDK 8 and an IDE with its own compiler, like Eclipse, you have to update the IDE to a version with Java 8 support, even if you are not using the newer Java 8 features.

The reason is that the [应该是指Eclipse] compiler must be able to load the newer class files of the JRE(应该是指JRE8) in order to compile your software which references these classes.

Sometimes you can get away with an older compiler when it ignores the newer version number of the class files. But some types will confuse older class file parsers as they use new features, notably(尤其是) AnnotatedElement, which now has default methods, and Map.Entry, an interface which now has static methods.

It seems that Eclipse does not make a difference between references for which no class file could be found and class files it failed to read when saying “«classname» cannot be resolved”.

可以看出,出问题的不是JRE/JDK什么的,是IDE的问题。

本地解决办法:
降级到JDK7,加入rt.jar到/WebContent/WEB-INF/lib下。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值