title: Error: How to read empty cell in Excel
body: <p>I'm trying to read data from excel using POI. How can I check if that is an empty cell?</p>
  
  <p>I don't know what is missing I think this should be working:</p>
  
  <pre><code>java.util.Iterator&lt;Row&gt; rows = worksheet.rowIterator();
  
  HSSFRow row = (HSSFRow) rows.next();
  HSSFCell cellF1 = (HSSFCell) row.getCell(5);
  if(cellF1.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
    String val = "";
  }
  </code></pre>
  
  <p>I got error in if statement (null pointer), but only if I use this I can check that:</p>
  
  <pre><code>   while (rows.hasNext()) {
      HSSFRow row = (HSSFRow) rows.next();
      java.util.Iterator&lt;Cell&gt; cells = row.cellIterator();
      while (cells.hasNext()) {
        HSSFCell cell = (HSSFCell) cells.next();
        if(cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
          String emptytype = "";
          System.out.println("empty");
        }
      }
    }
  </code></pre>