0

I'm using this program in Keyword driven framework for selenium web driver tool. But due to this program i'm getting null pointer exception every time i tried to debug the code but cant find any solution. please suggest me the solution for that error.

package utility;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;



import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;

public class ExcelUtils {

  private static HSSFSheet ExcelWSheet;
  private static HSSFWorkbook ExcelWBook;
  private static HSSFCell Cell;

 //This method is to set the File path and to open the Excel file
 //Pass Excel Path and SheetName as Arguments to this method
 public static void setExcelFile(String Path,String SheetName) throws Exception 
  {
      FileInputStream ExcelFile = new FileInputStream(Path);
      ExcelWBook = new HSSFWorkbook(ExcelFile);
      ExcelWSheet = ExcelWBook.getSheet(SheetName);
     }

 //This method is to read the test data from the Excel cell
 //In this we are passing parameters/arguments as Row Num and Col Num
 public static String getCellData(int RowNum, int ColNum) throws Exception{
 Cell = ExcelWSheet.getRow(RowNum).getCell(ColNum);
 System.out.println(Cell);
    String CellData = Cell.getStringCellValue();
    System.out.println("."+CellData);
    return CellData;
}


}
Amu
  • 1
  • 1
    which line is throwing null pointer exception? Have you used setExcelfile before getExceldata? – santhosh kumar Jun 20 '17 at 09:00
  • 1
    Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Guy Jun 20 '17 at 09:03
  • the error is:- Exception in thread "main" java.lang.NullPointerException at utility.ExcelUtils.getCellData(ExcelUtils.java:34) – Amu Jun 20 '17 at 11:47

0 Answers0