Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoSuchMethodError: org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl.getTrList()Ljava/util/List while using Apache POI library

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 ?

like image 201
Pawel Kozela Avatar asked Dec 11 '22 02:12

Pawel Kozela


1 Answers

A quick peek at Grepcode tells that the missing method is supported in v1.1 of ooxml-schemas. Also the v1.0 doesn't seem to contain such a method (it only contains a getTrArray() method).

So you may want to use ooxml-schemas-1.1.jar instead of ooxml-schemas-1.0.jar.

Here's the maven dependency of the version you should use at the very least:

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>ooxml-schemas</artifactId>
    <version>1.1</version>
</dependency>
like image 139
mystarrocks Avatar answered Dec 13 '22 15:12

mystarrocks