Getting NullPointerException while reading data from a cell | Selenium Forum
M
Posted on 09/02/2016
Hi Ashish,
I am trying to run the below code for reading data from the excel sheet - Employee.
I am using the "Xls_Reader.java" file.

public class Reading_xls_files {

public static void main(String[] args){
Xls_Reader datatable=new Xls_Reader("C:\\testing\\TestData.xlsx");
int r = datatable.getRowCount("Employee");
System.out.println(r);
String z = datatable.getCellData("Employee", "Emp ID", 3);
System.out.println(z);

But I am always getting java.lang.NullPointerException. I am not able to figure out the reason. Can you please help?

M
Replied on 09/02/2016

which line are you getting the error?


M
Replied on 10/02/2016

The error is in the line - [color=#008040:a2gorjwn]String z = datatable.getCellData("Employee", "Emp ID", 3);[/color:a2gorjwn]

Below is the output error -

[color=#0000BF:a2gorjwn]java.lang.NullPointerException
row 3 or column Emp ID does not exist in xls
at Xls_Reader.getCellData(Xls_Reader.java:70)
at Reading_xls_files.main(Reading_xls_files.java:7)[/color:a2gorjwn]


M
Replied on 10/02/2016

what is at TestData.xlsx (sheet name: "Employee" ). send a screen shot.

xls_reader cannot read the file.


M
Replied on 11/02/2016

[attachment=0:g0i74o3h]TestData.xlsx[/attachment:g0i74o3h]Please find attached the spreadsheet.


M
Replied on 11/02/2016

problem is with excell sheet


M
Replied on 12/02/2016

Thank you so much. The error is not coming now with the excel sheet which you gave. But I could not figure out what was wrong with the excel which I had prepared. Can you please let me know so that I dont repeat it again.


M
Replied on 12/02/2016

i just deleted the columns and made it again. it must have been some formating issue.


M
Replied on 12/02/2016

OK. Thank you.