| 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: 1098
|
|
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: 32827
|
|
|
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: 1098
|
|
|
could you post a sceen shot, as I am not following that link, sorry
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19230
|
|
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
How To Ask Questions How To Answer Questions
|
 |
James Boswell
Ranch Hand
Joined: Nov 09, 2011
Posts: 657
|
|
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.
|
 |
 |
|
|
subject: NullPointer Exception while using Apache POI
|
|
|