Java Null pointer exception thrown when checking length of blank excel cell

Krishnakumar T

Context: Null pointer exception thrown when checking the length of blank excel cell.

Please help to fix the exception.

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

}
SANTOSHKUMAR SINGH

Add null check in if condition.

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Java null pointer exception after checking if null

Null Pointer Exception When Checking If SharedPrefs Equals Null

Null pointer exception when working with generics in java

null pointer exception in java when coding

Java: null pointer exception when unboxing Integer?

Null Pointer Exception Java

Kotlin null pointer when checking for null state

Class becomes null when exception is thrown

Null pointer exception when checking for permission with android.content.Context.checkPermission

Sonar Cube "null pointer exception could be thrown" : False positive?

What is the exception that should be thrown when user input is blank?

Java - code will always throw a Null Pointer Exception when no Property is present?

Null Pointer exception when trying to return HashMap value in java

Java Null Pointer exception when querying SQLite Database in Android

C - Segmentation fault when checking if a pointer is NULL

Android - Java null pointer exception

Null pointer exception in java ArrayList

Java Multithreading null pointer exception

Weird Java Null Pointer Exception

JAVA: Null Pointer Exception error

java null pointer exception JMenuBar

Null Pointer Exception (Java) [EDIT!]

Is there a ?. operator for Java to perform null pointer checking?

Exception when clicking JTree (null pointer exception)

Exception thrown when trying to change a pointer in a void function

Are stack traces generated when a Java exception is thrown?

Java: Is There Any Way to Specify When an Exception Will be Thrown?

Creating Json file from Excel and want to pass null when cell is blank but having difficulty finding the right syntax

Checking for null pointer exception in an array in Jenkins scripted pipeline method