POI 5.0.0 - 获取 NoSuchMethodError - CTPPrDefault.getPPr() - CTPPrGeneral

问题描述 投票:0回答:1

迁移到 POI 5.0.0 后,我收到此错误:

java.lang.NoSuchMethodError: org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPrDefault.getPPr()Lorg/openxmlformats/schemas/wordprocessingml/x2006/main/CTPPrGeneral;
    at org.apache.poi.xwpf.usermodel.XWPFStyles.setStyles(XWPFStyles.java:145)
    at org.apache.poi.xwpf.usermodel.XWPFStyles.onDocumentRead(XWPFStyles.java:84)
    at org.apache.poi.xwpf.usermodel.XWPFDocument.onDocumentRead(XWPFDocument.java:207)
    at org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:169)
    at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:126)

这个 CTPPrGeneral 课程放在哪里? 我尝试了 poi-ooxml-full 5.0.0、poi-ooxml-lite 5.0.0、poi-ooxml-schemas 4.1.2 - 没有 CTPPrGeneral 类。

在 Google 中搜索没有帮助。看起来只在 XWPFDefaultParagraphStyle 类中提到过。

apache-poi
1个回答
6
投票

新的 Apache POI 5.0.0 需要

poi-ooxml-lite-5.0.0.jar
poi-ooxml-full-5.0.0.jar
。两者都包含
org/openxmlformats/schemas/wordprocessingml/x2006/main/CTPPrGeneral
并且
org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPrDefault
有一个返回
getPPr()
的方法
CTPPrGeneral

您的问题是由于类路径中还有

ooxml-schemas-1.4.jar
或更旧的内容所致。
org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPrDefault
有一个方法
getPPr()
,它返回
CTPPr
not
CTPPrGeneral
。这就是为什么
java.lang.NoSuchMethodError
。 Apache POI 5.0.0 代码调用
CTPPrDefault.getPPr
并期望得到
CTPPrGeneral
,但旧的
ooxml-schemas-1.4.jar
导出
CTPPrDefault
,其中
getPPr
not 返回该类型。

当使用 Apache POI 5.0.0 时,请确保您的类路径 only 包含

poi-ooxml-lite-5.0.0.jar
poi-ooxml-full-5.0.0.jar
不包含
ooxml-schemas-1.4.jar
甚至旧版本的
ooxml-schemas

© www.soinside.com 2019 - 2024. All rights reserved.