I am trying to insert text into a blank cell
getRow( 0 ).getCell( 0 ).setCellValue( 'Hat Selection' )
and I keep getting
Cannot invoke method setCellValue() on null object
Why can't I insert text into this blank cell? How can I?
I am trying to insert text into a blank cell
getRow( 0 ).getCell( 0 ).setCellValue( 'Hat Selection' )
and I keep getting
Cannot invoke method setCellValue() on null object
Why can't I insert text into this blank cell? How can I?
In case any of your object is null, you should first create it and then should set value on that. use createRow if you have not created the row already.
sheet.createRow(0);
if you have already created the row, but not the respective cell then first create the respective cell and then put the desired value. use
sheet.getRow(0).createCell(0).setCellValue(value);
Or you can combine all
sheet.createRow(0).createCell(0).setCellValue(value);
As I showed you in the other question you asked (but seemingly ignored the answer to)
Scriptom Groovy formating Excel Examples
you need to call createCell
when creating a new cell
Your program thinks that getRow(0).getCell(0) is null, NOT a cell. That's why you can't set the value because null doesn't have a setCellValue() method.
I don't know what sort of structure you're using but I'd check to make sure you're initializing first a table then each cell in said table sometime before you try to invoke this line of code. That way, each cell exists regardless of whether or not it actually has a text value.