You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Scott Callaghan <sc...@yahoo.com> on 2010/01/11 22:25:45 UTC
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
Re: Null Pointer Exception in WorkbookFactory.create(input-stream)
Posted by Scott Callaghan <sc...@yahoo.com>.
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 <sc...@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
Re: Null Pointer Exception in WorkbookFactory.create(input-stream)
Posted by Ramin Assisi <ra...@googlemail.com>.
Hi all POI Users,
we would like to inform you that we have started to develop Java
components to view and edit OOXML documents on the basis of POI.
See: http://assisi.eu.com
These components can help you to verify POI document generations. We
would appreciate any ideas.
Ramin
Applied Soft Ltd.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Null Pointer Exception in WorkbookFactory.create(input-stream)
Posted by Scott Callaghan <sc...@yahoo.com>.
Hi Nick,
Thanks for the response. I am happy to send you the file that I used.
I am little new to POI. How do I upload the file? Is there a link to do this? I can also attach the file and send it directly to your email address.
- Scott
________________________________
From: Nick Burch <ni...@alfresco.com>
To: POI Users List <us...@poi.apache.org>
Sent: Tue, January 12, 2010 5:48:58 AM
Subject: Re: Null Pointer Exception in WorkbookFactory.create(input-stream)
On Mon, 11 Jan 2010, Scott Callaghan wrote:
> I get a null pointer exception when I use a WorkbookFactory.create()
>
> 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)
This looks to me like there's something corrupt in the relationship definitions in your file. Can you upload the file so we can take a look?
(When you pass in an input stream, we have to do an in-memory buffer/copy to work on it. You'll save memory by passing the file directly to opcpackage, but that requires you to know it's xssf ahead of time)
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Null Pointer Exception in WorkbookFactory.create(input-stream)
Posted by Nick Burch <ni...@alfresco.com>.
On Mon, 11 Jan 2010, Scott Callaghan wrote:
> I get a null pointer exception when I use a WorkbookFactory.create()
>
> 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)
This looks to me like there's something corrupt in the relationship
definitions in your file. Can you upload the file so we can take a look?
(When you pass in an input stream, we have to do an in-memory buffer/copy
to work on it. You'll save memory by passing the file directly to
opcpackage, but that requires you to know it's xssf ahead of time)
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org