异常 java.lang.reflect.InvocationTargetException
报错信息
Exception in thread "main" org.apache.poi.POIXMLException: org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
at org.apache.poi.xslf.usermodel.XMLSlideShow.<init>(XMLSlideShow.java:82)
at org.apache.poi.xslf.usermodel.XMLSlideShow.<init>(XMLSlideShow.java:68)
at demo.ppt.Graph2Ppt.main(Graph2Ppt.java:59)
Caused by: org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
at org.apache.poi.xslf.usermodel.XSLFFactory.createDocumentPart(XSLFFactory.java:66)
at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:403)
at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:155)
at org.apache.poi.xslf.usermodel.XMLSlideShow.<init>(XMLSlideShow.java:80)
... 2 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.apache.poi.xslf.usermodel.XSLFFactory.createDocumentPart(XSLFFactory.java:64)
... 5 more
Caused by: java.lang.ExceptionInInitializerError
at org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument$Factory.parse(Unknown Source)
at org.apache.poi.xslf.usermodel.XSLFSlideMaster.<init>(XSLFSlideMaster.java:68)
... 10 more
Caused by: java.lang.NullPointerException
at org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(XmlBeans.java:769)
at org.openxmlformats.schemas.presentationml.x2006.main.SldMasterDocument.<clinit>(Unknown Source)
... 12 more
所有jar包
过程及原因
在网上找到两种原因:jar包冲突、myeclipse的jdk版本和系统版本不匹配。
1.经检查,jdk版本一样。
2.将所有jar包删除,再根据报错信息一一导入,还是出现同样的错误。清理的myeclipse的缓存还是没用。
最后发现实际原因是我重装了系统,项目代码是之前就写好了的。重新导入项目后就出现上文的异常信息。
感觉还是jar包冲突的问题。
解决方法
新建项目,copy代码,导入jar包。运行,ok。
最后
jar包是java操作ppt的,可以参考。