I'm trying to make work a piece of code to read a docx file, but it fails for some strange reason.
It fails on this line:
XWPFDocument document = new XWPFDocument(new FileInputStream(filepath));
Stack trace:
Exception in thread "main" java.lang.NoSuchMethodError: org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl.getTrList()Ljava/util/List;
at org.apache.poi.xwpf.usermodel.XWPFTable.<init>(XWPFTable.java:106)
at org.apache.poi.xwpf.usermodel.XWPFDocument.onDocumentRead(XWPFDocument.java:151)
at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:159)
at org.apache.poi.xwpf.usermodel.XWPFDocument.<init>(XWPFDocument.java:124)
at helper.JavaHelper.readTableDataFull(JavaHelper.java:84)
at helper.JavaHelper.main(JavaHelper.java:138)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
I have those jars:
- dom4j-1.6.1.jar
- xmlbeans-2.3.0.jar
- poi-3.9-20121203.jar
- poi-scratchpad-3.9-20121203.jar
- poi-ooxml-3.9-20121203.jar
- ooxml-schemas-1.0.jar
Looks like it should work to me (I have also tried with newer poi libs – same error).
Any ideas ?
Best Answer
A quick peek at Grepcode tells that the missing method is supported in
v1.1
ofooxml-schemas
. Also thev1.0
doesn't seem to contain such a method (it only contains agetTrArray()
method).So you may want to use
ooxml-schemas-1.1.jar
instead ofooxml-schemas-1.0.jar
.Here's the maven dependency of the version you should use at the very least: