Getting null pointer exception in creating cell in Apache POI

五迷三道 提交于 2019-12-04 18:10:54

Unfortunately, the cell is currently null not a blank cell. Placing data on the specified sheet makes it blank. You might want to create the cell first then check if it is a blank cell rather than null.

**XSSFCell cell = row.createCell(1);

if (cell == Cell.CELL_TYPE_BLANK){
   cell.setCellType(Cell.CELL_TYPE_STRING);
   cell.setCellValue("Apple");
}   

This would led to incompatible types.

Instead do this:

if (cell.getCellType() == Cell.CELL_TYPE_BLANK){
    cell.setCellType(Cell.CELL_TYPE_STRING);
    cell.setCellValue("Apple");
}   
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!