NoSuchMethodError in main thread while reading xlsx using apache poi

前端 未结 3 2017
隐瞒了意图╮
隐瞒了意图╮ 2021-01-12 14:07

my code is

[...]
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.X         


        
相关标签:
3条回答
  • 2021-01-12 14:26

    This usually indicates that you somehow drag in outdated XML Parser interfaces, e.g. via some transient dependency to an old xml-api version or an outdated xerces jar, which is usually not needed any more at all as Java 6 provides all the XML parsing functionality out of the box.

    See this discusion for some more details.

    0 讨论(0)
  • 2021-01-12 14:33

    Recent versions of poi-ooxml require you to use at least java 6. The method in question was only added since java 6. Consider upgrading your java version.

    From the official docs,

    The OOXML jars require a stax implementation, but now that Apache POI requires Java 6, that is provided by the JRE and no additional stax jars are required. The OOXML jars used to require DOM4J, but the code has now been changed to use JAXP and no additional dom4j jars are required.

    *Emphasis mine.

    Since the question was edited, I'm specifying the build this method was added:

    java 1.6.0_18

    So a minimum of this version must be used in OP's case.

    0 讨论(0)
  • 2021-01-12 14:35

    I ran into exactly the same issue as you, and I found the following jar files have to be used to solve the program:

    • poi-bin-3.8.zip
    • opencsv-2.3.jar
    • poi-ooxml-3.8.jar
    • poi-ooxml-schemas-3.8.jar
    • xmlbeans-2.3.0.jar
    • dom4j-1.6.1.jar

    Newer version will bring trouble.

    0 讨论(0)
提交回复
热议问题