使用Dom4j解析xml出现非法反射异常,求大佬帮忙解决下

steretype 2018-06-19 04:55:03
public class TestDom4j {

public static void main(String[] args) throws Exception{
selectSin();

}
//查询p.xml下的第一个name元素
public static void selectSin() throws Exception {
SAXReader sr=new SAXReader();//创建解析器
Document document=sr.read("src/p.xml");
Element element =document.getRootElement();//得到根元素
List<Element> list=element.elements("p1");
Iterator<Element> i=list.iterator();
while(i.hasNext()) {
Element name=i.next();
String str=name.getText();
System.out.println(str);
}
}
}
异常
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.dom4j.io.SAXContentHandler (file:/D:/eclipse-workspace/day06/lib/dom4j-1.6.1.jar) to method com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser$LocatorProxy.getEncoding()
WARNING: Please consider reporting this to the maintainers of org.dom4j.io.SAXContentHandler
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
...全文
1295 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
baoyiquan2018 2019-06-17
  • 打赏
  • 举报
回复
使用2.1.1版本
satoyama(^^) 2019-04-21
  • 打赏
  • 举报
回复
现在官网只有dom4j-2.1.1,没有dom4j-2.1.0,但我用这个2.1.1的jar包,找不到SAXReader,build path 这些我都是没问题的,我用dom4j-1.6.1是可以找到SAXReader,但我用的是JDK11.......会显示楼主上面的问题,用2.1.1找不到SAXReader,不知道为什么
stacksoverflow 2018-06-20
  • 打赏
  • 举报
回复
引用 3 楼 weixin_42127327 的回复:
解决了 感谢大佬帮忙
结帖。
steretype 2018-06-19
  • 打赏
  • 举报
回复
解决了 感谢大佬帮忙
stacksoverflow 2018-06-19
  • 打赏
  • 举报
回复
或者降级JDK,不要用JDK9
stacksoverflow 2018-06-19
  • 打赏
  • 举报
回复
升级dom4j到2.1.0

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧