nullpointerexception reading from excel data in selenium webdriver

I have tried to solve the problem for read from excel data, i’m getting error, so please help me. my code:

 public class ExcelData { public String[][] getCellData(String path, String sheetName) throws InvalidFormatException, IOException { FileInputStream stream = new FileInputStream(path); Workbook workbook = WorkbookFactory.create(stream); Sheet sheet = workbook.getSheet(sheetName); int rowcount = sheet.getLastRowNum(); int cellcount = sheet.getRow(1).getLastCellNum(); String data[][] = new String[rowcount][cellcount]; for (int i = 1; i <= rowcount; i++) { Row row = sheet.getRow(i); for (int j = 0; j<= cellcount; j++) { Cell cell = row.getCell(j); if (cell.getCellType()==cell.CELL_TYPE_STRING) { data[i - 1][j] = cell.getStringCellValue(); } else { data[i - 1][j] = String.valueOf(cell.getNumericCellValue()); } } } return data; } } 
2.main classs:
 @DataProvider(name="testdata") public String[][] getExcelData() throws InvalidFormatException, IOException{ ExcelData read = new ExcelData(); return read.getCellData("D:\\DAutomate\\Testdata\\Logincredentials.xlsx", "Sheet1"); } @Test(dataProvider="testdata") public void LoginDetails(String email, String password) throws Exception { driver.findElement(By.xpath("//span[@class='user-login']")).click(); Thread.sleep(2000); driver.findElement(By.id("UserName")).clear(); driver.findElement(By.id("UserName")).sendKeys(email); driver.findElement(By.id("Password")).clear(); driver.findElement(By.id("Password")).sendKeys(password); driver.findElement(By.name("login")).click(); Thread.sleep(3000); } 

Add Comment
  • 0 Answer(s)
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.