File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes NullPointer Exception while using Apache POI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "NullPointer Exception while using Apache POI" Watch "NullPointer Exception while using Apache POI" New topic
Author

NullPointer Exception while using Apache POI

Paras Ahuja
Ranch Hand

Joined: May 22, 2012
Posts: 62

if(cell8[j].getCellType()==Cell.CELL_TYPE_BLANK) throws a NullPointerException. Dont know why...
Please help.....

Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

You are creating an array with 8 elements in it, but you are not actually putting anything into the array, so you currently have 8 null array elements.

missed the lines ahead where you fill the array in.

but you are still getting a null pointer exception because there is nothing in the element.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38363
    
  23
And fabs[j] = new String(); should be deleted. It does nothing. You might do well to get rid of the assignment to null in line 13; that is another problem waiting to happen later on.
Paras Ahuja
Ranch Hand

Joined: May 22, 2012
Posts: 62
But you see this is these rows are 8th in list in the template i'm reading. I have same code for row1,row2,......,row7 before this one. But when i try to upload data from this excel sheet into my GUI, the error occurs at row8 (as i specified before). I am filling only row1 cells to be read and leaving all the remaining cells blank.
Why the error is not generated for row2,row3,.....row7?
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

could you post a sceen shot, as I am not following that link, sorry
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

row8[j].getCell(3) will return null if the cell is not defined (whatever that means). There are two quick fixes:
1) Check if row8[j] != null before using it.
2) Replace row8[j].getCell(3) with row8[j].getCell(3, Row.CREATE_NULL_AS_BLANK).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

It has occurred because cell8[j] is null. You will need to debug to find out why.

On a side note, get into the habit of using braces for single line if conditions. The no braces style is horrible and prone to creating bugs.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointer Exception while using Apache POI