How to read data from Blank cell or cell having null value | Selenium Forum
M
Posted on 23/07/2016
Requirement: The data from excel should be read until an Blank cell is encountered.

Both the below code are reading the data from excel until a null or blank cell is encountered. The code does not move forward and give a java.lang.NullPointerException. What should be the correct code? Why the isempty() function do not work here.

while(!xls.getdata(1,dataStartRowNum,0).equals(""))
{
System.out.println(xls.getdata(1,dataStartRowNum,0));
dataStartRowNum++;
dataRows++;
}

or

while(!xls.getdata(1,dataStartRowNum,0).isempty())
{
System.out.println(xls.getdata(1,dataStartRowNum,0));
dataStartRowNum++;
dataRows++;
}

M
Replied on 24/07/2016

you cannot it will give an error.


M
Replied on 25/07/2016

when is isempty() method used for and please tell me how do I handle null/blank values in excel?


M
Replied on 25/07/2016

I got this code working by surrounding it with try catch block. Let me know if this is correct way of doing and also when isempty() used.

try {
while(!xls.getdata(1,dataStartRowNum,0).equals(""))
{
System.out.println(xls.getdata(1,dataStartRowNum,0));
dataStartRowNum++;
dataRows++;
}
} catch (Exception e1) {

e1.printStackTrace();
}


M
Replied on 25/07/2016

try catch will work fine.


which class has this [color=#FF0000:2cr1sa5m]isempty() [/color:2cr1sa5m] function?


M
Replied on 26/07/2016

isempty() is used to determine if the length of the string is 0


M
Replied on 26/07/2016

http://www.tutorialspoint.com/java/lang/string_isempty.htm