You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by satcal <ko...@gmail.com> on 2012/09/20 01:49:40 UTC

NullpointerException on loading xlsx file using Apache POI


Am tryng to read a file using Apache POI 3.8 in mac osx environment, which
is created in Windows using Open XML SDK 2.0 for Microsoft Office, am
getting null pointer exception as it is unable to load the xlsx file. Below
is the stack trace. I am able to open the file and view it.

The same code works for the files that I create in mac os env. If i open and
save the file before processing, am not having any issue and the file size
increases after saving the file

Any clues why am i getting below error.

Caused by: java.lang.NullPointerException
        at
org.apache.poi.xssf.usermodel.XSSFWorkbook.onDocumentRead(XSSFWorkbook.java:253)
        at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:159)
        at
org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:183)
        at
org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:73) 

The class looks like below, with utility methods, did not copy the entire
class. but this happens at line wb = new XSSFWorkbook(bis) while creating
the workbook. I tried couple of options like WorkbookFactory.create(bis)
instead of XSSFWorkbook, but the error remains same, issue is mainly with
the file content. 

public class XLSXReader {

    private BufferedInputStream bis;
    private boolean hasNext = true;
    int skipLines;

    private boolean linesSkiped;

    //   The default line to start reading.
    public static final int DEFAULT_SKIP_LINES = 0;

    private XSSFWorkbook wb =null;
    private XSSFSheet sheet=null;
    private int noOfCols;

    public XLSXReader(InputStream is){
        bis = new BufferedInputStream(is);
        this.noOfCols=0; 
        try {
            wb = new XSSFWorkbook(bis); 
            sheet = wb.getSheetAt(0);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

// with basic utility methods ....
}

java apache-poi openxml-sdk xlsx 



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/NullpointerException-on-loading-xlsx-file-using-Apache-POI-tp5710967.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org