Java 空指针异常在检查空白 Excel 单元格的长度时引发



上下文:检查空白 Excel 单元格的长度时引发空指针异常。

请帮助修复异常。

int lastRowNum = sh.getLastRowNum();
for (int i = 1; i < (lastRowNum+1); i++) {
    Row row = sh.getRow(i);
    System.out.println(i);
    // Null pointer exception throws for below if condition
    if (row.getCell(0).toString().length() == 0) {
        actions.operations(objectRepository, row.getCell(1).toString(), row.getCell(2).toString(), row.getCell(3).toString(), row.getCell(4).toString());
    }
    else {
        System.out.println("Test Case: " + row.getCell(0).toString() + " Started");
    }
}

添加空检入 if 条件。

if(row.getCell(0) ==null || row.getCell(0).toString().length()==0){

最新更新