POI 5.0.0 - 获取 NoSuchMethodError - CTPPrDefault.getPPr() - CTPPrGeneral
POI 5.0.0 - get NoSuchMethodError - CTPPrDefault.getPPr() - CTPPrGeneral
迁移到 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 class 放在哪里?
我尝试了 poi-ooxml-full 5.0.0、poi-ooxml-lite 5.0.0、poi-ooxml-schemas 4.1.2 - 没有 CTPPrGeneral class.
在 Google 中搜索没有帮助。看起来它只在 XWPFDefaultParagraphStyle class.
中提到
新的 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()
其中 returns CTPPrGeneral
.
您的问题是由于 class 路径中也有 ooxml-schemas-1.4.jar
或更早版本。 org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPrDefault
有一个方法 getPPr()
returns CTPPr
和 not CTPPrGeneral
。这就是 java.lang.NoSuchMethodError
的原因。 apache poi 5.0.0
代码调用 CTPPrDefault.getPPr
并期望 CTPPrGeneral
但旧的 ooxml-schemas-1.4.jar
导出 CTPPrDefault
其中有 getPPr
not 返回那个类型。
确保您的class路径仅包含poi-ooxml-lite-5.0.0.jar
或poi-ooxml-full-5.0.0.jar
但不ooxml-schemas-1.4.jar
甚至更旧版本的 ooxml-schemas
当使用 apache poi 5.0.0
时。
迁移到 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 class 放在哪里? 我尝试了 poi-ooxml-full 5.0.0、poi-ooxml-lite 5.0.0、poi-ooxml-schemas 4.1.2 - 没有 CTPPrGeneral class.
在 Google 中搜索没有帮助。看起来它只在 XWPFDefaultParagraphStyle class.
中提到新的 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()
其中 returns CTPPrGeneral
.
您的问题是由于 class 路径中也有 ooxml-schemas-1.4.jar
或更早版本。 org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPrDefault
有一个方法 getPPr()
returns CTPPr
和 not CTPPrGeneral
。这就是 java.lang.NoSuchMethodError
的原因。 apache poi 5.0.0
代码调用 CTPPrDefault.getPPr
并期望 CTPPrGeneral
但旧的 ooxml-schemas-1.4.jar
导出 CTPPrDefault
其中有 getPPr
not 返回那个类型。
确保您的class路径仅包含poi-ooxml-lite-5.0.0.jar
或poi-ooxml-full-5.0.0.jar
但不ooxml-schemas-1.4.jar
甚至更旧版本的 ooxml-schemas
当使用 apache poi 5.0.0
时。