Hi,
I get a null pointer exception when I use a WorkbookFactory.create() for a XSSF
file. I am able to use it successfully with HSSF.
Here is my code:
FileInputStream fin = new FileInputStream(inFile);
Workbook wb = null;
try {
wb = WorkbookFactory.create(fin);
}
catch (Exception e) {
System.out.println("Workbook object could not be created");
e.printStackTrace();
return;
}
I verified that the inFile is an ".xlsx" file, it exists and can be opened by
Excel. The null pointer exception stack looks as follows:
java.lang.NullPointerException
at org.apache.poi.util.PackageHelper.copy(PackageHelper.java:129)
at org.apache.poi.util.PackageHelper.clone(PackageHelper.java:87)
at org.apache.poi.util.PackageHelper.clone(PackageHelper.java:44)
at org.apache.poi.POIXMLDocument.ensureWriteAccess(POIXMLDocument.java:185)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:169)
at
org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:63)
I am using POI 3.6. My class path includes only the following jar files from
POI distribution:
poi-3.6-20091214.jar
poi-ooxml-3.6-20091214.jar
poi-ooxml-schemas-3.6-20091214.jar
xmlbeans-2.3.0.jar
Earlier, I had been getting the NoClassDefFoundError but the problem
disappeared after I successively included more of the jar files from the
distribution.
I would appreciate any answers or suggestions.
- Scott