null pointer exception apache poi

前端 未结 2 1310
借酒劲吻你
借酒劲吻你 2021-01-11 14:47

hi we\'ve been reading xls and xlsx file using apache poi ing our java program, the problem is we are getting null pointer exception with two reasons.. the first 1 is the bl

2条回答
  •  醉话见心
    2021-01-11 15:27

    The issue is that you never test if the cell is null!

    if (cell == null)
    {
       System.out.println("Cell is Empty in Column:" + cols);
    
    } else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING)
    {
       //code
    }
    

    As a general matter, you should be careful while handling Cell.getCellType() function, since an empty cell could be either null or be a CELL_TYPE_BLANK.

提交回复
热议问题