org.apache.poi.POIXMLException:java.lang.reflect.InvocationTargetException,root cause nullpointer exception(xmlbeans.jar)

时间:2016-03-17 06:38:55

标签: java eclipse jar apache-poi xssf

我正在尝试使用apache poi3.12读取.xlsx文件,3.14是最新的,我也尝试过。我已经包含了以下的罐子,

1.poi-3.12-20150511.jar 2.poi-OOXML-3.12-20150511.jar 3.poi-OOXML-架构 - 3.12-20150511.jar 4.ooxml-架构 - 1.0.jar 5.xmlbeans.2.3.0.jar 6.commons编解码器-1.9.jar 7.commons-测井1.1.3.jar

我正在使用jre 1.8_73,正如另一个问题所建议的那样,他从1.8升到1.8升,这对他有用。但在这里我使用的是最新的jre。

追踪:

Exception: org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:62)
at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:403)
at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:155)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:207)
at readfiles.ReadScsu.readFile(ReadScsu.java:54)
at hello1.hello1.doPost(hello1.java:48)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Exception:Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:60)
... 29 more
`Exception:Caused by: java.lang.ExceptionInInitializerError
at org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument$Factory.parse(Unknown Source)
at org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:44)
... 34 moreCaused by: java.lang.NullPointerException
at org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(XmlBeans.java:769)
at org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument.<clinit>(Unknown Source)
... 36 more`

我正在使用:

`` try { 


        InputStream   XlsxFileToRead  = this.getClass().getClassLoader()
        .getResourceAsStream("Week2OTSResult.xlsx");


                System.out.println("fs="+XlsxFileToRead.toString() );

                XSSFWorkbook wb = new XSSFWorkbook(XlsxFileToRead);//in debug mode, here is where the exception is caused.


              XSSFSheet sheet = wb.getSheetAt(0);


               System.out.println(sheet.getRow(5).getCell(7).toString());
                    System.out.println("\nin read  file2\n");

    }catch (FileNotFoundException fe)
    { 
           fe.printStackTrace(); 
    } 

    catch (IOException ie)
    { 
        ie.printStackTrace(); 
        } 

1 个答案:

答案 0 :(得分:2)

似乎问题可能与XMLBeans lib的版本有关。

建议XMLBeans 2.6.0与Apache POI一起使用,它现在是二进制发行包中提供的版本。