Reputation: 101
I am using Apache Poi in an Android application, but I have a problem with the update of xls file.
To change the value of a cell where there is already a value I have no problem, but I have a null pointer exeption when I change the value of empty cells.
I use the method setCellValue.
Upvotes: 3
Views: 136
Reputation: 3806
You may need to create the cell before you change the value of it. If a cell has no value it 'doesn't exist' so to speak and so you need to create it and then set it's value. You could try using the getCell() with mising rowPolicy to try and obtain a cell if their isn't currently one, like so:
myRow.getCell(7, Row.CREATE_NULL_AS_BLANK);//Should create cell if it is currently blank
Once you have the cell, try setting it's value as you have been doing.
Alternatively, try checking beforehand if you have a cell, e.g
if (myCell ==null) {
//Create cell code
Cell cell = row.createCell(0);
}
Good luck!
Upvotes: 3