Eclipse下Java EE项目OutputDocument.replace方法未定义求助
解决
OutputDocument.replace(Element, String)方法未定义问题 问题回顾
在Eclipse开发Java EE项目时,使用Jericho HTML库处理HTML元素时碰到了如下报错:
The method replace(Element, String) is undefined for the type OutputDocument
对应的代码使用场景如下:
(Iterator i = linkStartTags.iterator(); i.hasNext();) { Element el = (Element)i.next(); Attributes attributes = el.getAttributes(); String rel = attributes.getValue(atributo); if ((rel != null) && (!"".equalsIgnoreCase(rel))) { if ((valores != null) && (valores.containsKey(rel))) { String valor = (String)valores.get(rel); outputDocument.replace(el, valor); } } }
已经导入au.id.jericho.lib.html.OutputDocument库,但问题依然存在。
问题根源与解决办法
这个问题的核心原因是Jericho HTML版本不兼容:
- 你之前使用的
jericho-html-2.1版本中,OutputDocument类并未提供replace(Element, String)这个方法; - 当更换为
jericho-html-2.3版本后,该方法已被添加到OutputDocument类中,因此报错消失,代码可以正常运行。
后续排查小提示
如果以后再遇到类似的「方法未定义」问题,可以优先从这两点入手:
- 确认当前使用的库版本是否与代码依赖的版本匹配;
- 查阅对应版本的API文档,验证方法是否在该版本中存在。
内容的提问来源于stack exchange,提问作者Diebug
相关产品推荐
相关产品推荐

