I want to sum up all values in the cells of the rows and write the aggregated value in the bottom of the table. I use this code
double Sum[] = new double[sheet.getRow(0).getLastCellNum()];
for (int i = 1; i < LastCellNum; i++)
{
Sum[i - 1] = 0;
for (int j = 1; j <= LastRowNum; j++)
{
cell = sheet.getRow(j).getCell(i);
if (cell != null)
{
try
{
Sum[i - 1] = Sum[i - 1] + cell.getNumericCellValue();
}
catch (NumberFormatException | NullPointerException ex)
{
//Handle NumberFormat and NullPointer exceptions here
}
catch (Exception ex)
{
//Handle generic exception here}
}
}
}
System.out.println(Sum[i - 1]);
The code works properly and it could even print the Value of Sum, but after that I have java.lang.NullPointerException
.
All the selected Cells in my file are either empty or contain numbers.