1

I am working on a class to read data from Excel files using the Apache POI. Specifically, I want to loop over entries in the first column until cells are emtpy. I just figured that the following code gives me a null exception:

while(sheet.getRow(i).getCell(0) != null) {
      // Do something
      i++;
}

However, after changing the code just by removing the getCell(0) it works perfectly fine without the null exception:

while(sheet.getRow(i) != null) {
      // Do something
      i++;
}

In either case I should get back null and then terminate the while loop. Why is the second example working without a null exception? I just don't see the reason.

Christoph
  • 97
  • 9

0 Answers0