I have an application which throws this error (happens only with xlsx-files):
java.lang.NullPointerException
at java.io.File.<init>(File.java:222)
at de.mpicbg.tds.core.ExcelLayout.openWorkbook(ExcelLayout.java:75)
The method ‘openWorkbook’ looks like this:
private void openWorkbook() throws IOException {
File excelFile = new File(fileName);
timestamp = excelFile.lastModified();
// open excel file
if (fileName.endsWith(".xlsx")) {
InputStream excelStream = new BufferedInputStream(new FileInputStream(excelFile));
this.workbook = new XSSFWorkbook((excelStream));
} else {
this.workbook = new HSSFWorkbook(new POIFSFileSystem(new FileInputStream(excelFile)));
}
}
If I execute everything in debug mode, everything goes smoothly and the error message does not appear. I don’t have any explanation for this behaviour nor any idea how to fix it.
Can anybody help?
The error message says your
fileNameisnullIf you cannot reproduce this when debugging you can add a log message at the start of you method.
Instead of using a field which may or may not be set, I suggest you use a parameter.