Exception in thread "main" org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
at org.apache.poi.POIXMLFactory.createDocumentPart(POIXMLFactory.java:65)
at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:601)
at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:174)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:279)
at sanityTests.ApachePOI.main(ApachePOI.java:20)
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:56)
at org.apache.poi.POIXMLFactory.createDocumentPart(POIXMLFactory.java:62)
... 4 more
Caused by: java.lang.NoSuchMethodError: org.apache.xmlbeans.XmlOptions.setLoadEntityBytesLimit(I)Lorg/apache/xmlbeans/XmlOptions;
at org.apache.poi.POIXMLTypeLoader.<clinit>(POIXMLTypeLoader.java:50)
at org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:85)
... 10 more

If I change the format of the file from xlsx to xls it works fine.Not sure how to resolve the error. I have included all the jars like xml-beans and poi jars. Still getting the error. Please help

1 Answer
1

You haven't provided any version numbers for any of your components. However, XmlOptions.setLoadEntityBytesLimit(int) was only added in XMLBeans version 2.6.0 (from August 2012), and will not be present in 2.4.0.

As far as I can tell, POI has used 2.6.0 itself for quite a long time, but somehow an older version of the library has been included in your runtime dependencies, and will need updating.

To sum up: include XMLBeans 2.6.0 in your project and POI will work fine.

Actually POI still tries to stay compatible with earlier versions of XMLBeans, so it should work, but still seems to have been broken in the latest release, see Bug 59195. As you said, using version 2.6.0 should solve the issue here.
– centicMar 18 '16 at 7:25

Good spot. When I read the changelog I could see 2.3.0 still listed as the minimum, 2.6.0 recommended - but that bug explains the discrepancy.
– Andrew ReganMar 18 '16 at 12:16