2017-03-18 18 views
0

コンテキスト:空白のExcelセルの長さをチェックするときにNULLポインタ例外がスローされます。空白のExcelセルの長さをチェックするときにJava Nullポインタ例外がスローされる

例外を修正するのを手伝ってください。

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"); 
    } 

} 
+7

[NullPointerExceptionがある、と私はそれをどのように修正すればよいか?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-の可能性のある重複i-fix-it) –

答えて

0

条件が満たされていればヌルチェックインを追加します。

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

ありがとうございます。有用。 –

+0

解答を受け入れられた回答としてマークしてください。 :) –

+0

完了............ –

関連する問題