poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Callaghan <sccll...@yahoo.com>
Subject Re: Null Pointer Exception in WorkbookFactory.create(input-stream)
Date Tue, 12 Jan 2010 05:51:19 GMT
OK - I found a simple work around that is adequate.

Instead of:

    wb = WorkbookFactory.create(fin);

I do:

    wb = new XSSFWorkbook(fin);

Alas, this forces my code to know which file is XSSF. However, I can live with that for now.

- Scott  

From: Scott Callaghan <sccllghn@yahoo.com>
To: user@poi.apache.org
Sent: Mon, January 11, 2010 4:25:45 PM
Subject: Null Pointer Exception in WorkbookFactory.create(input-stream)


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");

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:

    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:

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

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message