java.lang.NoClassDefFoundError while creating a .xlsx file using Apache POI

前端 未结 5 608
伪装坚强ぢ
伪装坚强ぢ 2021-01-23 16:21

I am trying to create a .xlsx file using Apache POI. This is my code:

FileOutputStream outputStream1=null;
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet          


        
相关标签:
5条回答
  • 2021-01-23 16:56

    As detailed on the Apache POI components page, to use the OOXML code like XSSF, you need both the poi and poi-ooxml jars on your classpath, along with their dependencies.

    The latest version of Apache POI, as of writing, is 3.10. I'd suggest you go download the binary release package, in there you'll find all the POI jars, along with all their dependencies. The components page will help you work out which you need, but for working with XSSF the short answer is you'll basically need all of them!

    0 讨论(0)
  • 2021-01-23 16:59

    Cause of NoClassDefFoundError is: Definition of class specified in exception was need to execute the code, but it could not be found under the specified package.

    Root cause: Usually it turns out that either jar file containing that Class definition was added or it was not added to build path.

    You can download apache POI jars for various releases here

    0 讨论(0)
  • 2021-01-23 17:06

    In my case, it works only if your app contains these libraries:

    compile files('libs/dom4j-1.6.1.jar')
    compile files('libs/stax-api-1.0.1.jar')
    compile files('libs/xmlbeans-2.6.0.jar')
    compile files('libs/poi-3.10.1-20140818.jar')
    compile files('libs/poi-ooxml-3.10.1-20140818.jar')
    compile files('libs/poi-ooxml-schemas-3.10.1-20140818.jar')
    

    You can download them here: here, all in the 'poi-bin-3.10.1-20140818.zip' archive.

    And please do not try to install a newer version, it will not work (at least for Android), only 3.10.1 and lower.

    0 讨论(0)
  • 2021-01-23 17:07

    I also think you do not import the poi-3.7.jar into your project! first, you should create a folder lib, then copy the jar package file to this lib,then switch to build path, you can google it.

    0 讨论(0)
  • 2021-01-23 17:11

    you need to download poi-ooxml-3.9.jar

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