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)

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


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