java.lang.NullPointerException at utility.ExcelUtils.getRowCount(ExcelUtils.java:49) at executionEngine.DriverScript.execute_TestCase(DriverScript.java:50) at executionEngine.DriverScript.main(DriverScript.java:45)

Hi,
Thank you so much for providing the knowledge.

When I run the selenium keyword driven frame work I am getting  the below mentioned error.How to fix this issue?

java.lang.NullPointerException
at utility.ExcelUtils.getRowCount(ExcelUtils.java:49)
at executionEngine.DriverScript.execute_TestCase(DriverScript.java:50)
at executionEngine.DriverScript.main(DriverScript.java:45)

Regards
Anju

Anju Default Asked on January 21, 2015 in Selenium WebDriver.
Add Comment
3 Answer(s)

Hi , i am facing same issue. the method array is not loading the methods from ActionKeywords class.
The method array is null. below is the code. Can you please provide solution.
Thank you.


package executionEngine;
import config.ActionKeywords;

import utility.ExcelUtils;

import java.lang.reflect.*;
public class DriverScript {
public static ActionKeywords actionKeywords;

public static String sActionKeyword;

//This is reflection class object, declared as 'public static'

//So that it can be used outside the scope of main[] method

public static Method method[];
//Here we are instantiating a new object of class 'ActionKeywords'

public DriverScript() throws NoSuchMethodException, SecurityException{

actionKeywords = new ActionKeywords();

//This will load all the methods of the class 'ActionKeywords' in it.

//It will be like array of method, use the break point here and do the watch

method =actionKeywords.getClass().getMethods();
}
public static void main(String[] args) throws Exception {
System.out.println(method.length);

// Declaring the path of the Excel file with the name of the Excel file

String sPath = "D://WorkspaceOne//KeyWordFramework//src//dataEngine//DataEngine.xlsx";
// Here we are passing the Excel path and SheetName as arguments to connect with Excel file

ExcelUtils.setExcelFile(sPath, "Test Steps");
//Hard coded values are used for Excel row & columns for now

//In later chapters we will replace these hard coded values with varibales

//This is the loop for reading the values of the column 3 (Action Keyword) row by row
for (int iRow=1;iRow<=7;iRow++){

//Storing the value of excel cell in sActionKeyword string variable
String sActionKeyword = ExcelUtils.getCellData(iRow, 3);
execute_Actions();

}

}
//This method contains the code to perform some action

//As it is completely different set of logic, which revolves around the action only,

//It makes sense to keep it separate from the main driver script

//This is to execute test step (Action)

private static void execute_Actions() throws Exception {

//This is a loop which will run for the number of actions in the Action Keyword class

//method variable contain all the method and method.length returns the total number of methods

//int totalmethods=method.length;
for(int i = 0;i < method.length;i++){

System.out.println(method[i]);//This is now comparing the method name with the ActionKeyword value got from excel

if(method[i].getName().equals(sActionKeyword)){

//In case of match found, it will execute the matched method

method[i].invoke(actionKeywords);

//Once any method is executed, this break statement will take the flow outside of for loop

break;
}

}

}

}

Nag Default Answered on April 15, 2015.
Add Comment

Hi, got solution. here is the code.

 package executionEngine;
import config.ActionKeywords;
 import utility.ExcelUtils;
 import java.lang.reflect.*;
public class DriverScript {
public static ActionKeywords actionKeywords;
 public static String sActionKeyword;
//This is reflection class object, declared as 'public static'
 //So that it can be used outside the scope of main[] method
public static Method method[];
//Here we are instantiating a new object of class 'ActionKeywords'
public DriverScript() throws NoSuchMethodException, SecurityException{
 actionKeywords = new ActionKeywords();
//This will load all the methods of the class 'ActionKeywords' in it.
 //It will be like array of method, use the break point here and do the watch
method =actionKeywords.getClass().getMethods();
}
public static void main(String[] args) throws Exception {
 // Declaring the path of the Excel file with the name of the Excel file
String sPath = "D://WorkspaceOne//KeyWordFramework//src//dataEngine//DataEngine.xlsx";
// Here we are passing the Excel path and SheetName as arguments to connect with Excel file
ExcelUtils.setExcelFile(sPath, "Test Steps");
 
DriverScript startEngine = new DriverScript();
 startEngine.execute_TestCase();
}
private void execute_TestCase() throws Exception {
for (int iRow=1;iRow<=7;iRow++){
 //Storing the value of excel cell in sActionKeyword string variable
 sActionKeyword = ExcelUtils.getCellData(iRow, 3);
execute_Actions();
 }
 }
//This method contains the code to perform some action
 //As it is completely different set of logic, which revolves around the action only,
 //It makes sense to keep it separate from the main driver script
 //This is to execute test step (Action)
 private static void execute_Actions() throws Exception {
 //This is a loop which will run for the number of actions in the Action Keyword class
 //method variable contain all the method and method.length returns the total number of methods
 //int totalmethods=method.length;
for(int i = 0;i < method.length;i++){
 //System.out.println(method[i]);
//This is now comparing the method name with the ActionKeyword value got from excel
 if(method[i].getName().equals(sActionKeyword)){
 //In case of match found, it will execute the matched method
 method[i].invoke(actionKeywords);
 //Once any method is executed, this break statement will take the flow outside of for loop
 break;
}
 }
 }
 }
 
Nag Default Answered on April 15, 2015.

thank u so much for the solution provided.
It worked.

on November 30, 2016.
Add Comment

Hi you! First of time, i would like to say thanks about your share knowledge.
I try to practise follow your example and i saw error like above.

Exception in thread “main” java.lang.NullPointerException
at utility.ExcelUtils.getCellData(ExcelUtils.java:23)
at executionEngine.DriverScript.execute_TestCase(DriverScript.java:44)
at executionEngine.DriverScript.main(DriverScript.java:35)

This is my code, just copy from your code and edit small thing.

package executionEngine;

import java.lang.reflect.Method;

import config.ActionKeywords;
import config.Constants;
import utility.ExcelUtils;

public class DriverScript {
//This is a class object, declared as ‘public static’
//So that it can be used outside the scope of main[] method
public static ActionKeywords actionKeywords;
public static String sActionKeyword;
//This is reflection class object, declared as ‘public static’
//So that it can be used outside the scope of main[] method
public static Method method[];

//Here we are instantiating a new object of class ‘ActionKeywords’
public DriverScript() throws NoSuchMethodException, SecurityException{
actionKeywords = new ActionKeywords();
//This will load all the methods of the class ‘ActionKeywords’ in it.
//It will be like array of method, use the break point here and do the watch
method = actionKeywords.getClass().getMethods();
}

public static void main(String[] args) throws Exception {

//Declaring the path of the Excel file with the name of the Excel file
String sPath = Constants.Path_TestData;

//Here we are passing the Excel path and SheetName to connect with the Excel file
//This method was created in the last chapter of ‘Set up Data Engine’
ExcelUtils.setExcelFile(sPath, Constants.Sheet_TestSteps);
DriverScript startEngine = new DriverScript();
startEngine.execute_TestCase();
}
//Hard coded values are used for Excel row & columns for now
//In later chapters we will use these hard coded value much efficiently
//This is the loop for reading the values of the column 3 (Action Keyword) row by row
//It means this loop will execute all the steps mentioned for the test case in Test Steps sheet
private void execute_TestCase() throws Exception {
for (int iRow = 1;iRow <= 20;iRow++){
//This to get the value of column Action Keyword from the excel
sActionKeyword = ExcelUtils.getCellData(iRow, Constants.Col_ActionKeyword);
//A new separate method is created with the name ‘execute_Actions’
//You will find this method below of the this test
//So this statement is doing nothing but calling that piece of code to execute
execute_Actions();
}
}

//This method contains the code to perform some action
//As it is completely different set of logic, which revolves around the action only,
//It makes sense to keep it separate from the main driver script
//This is to execute test step (Action)
private static void execute_Actions() throws Exception {
//This is a loop which will run for the number of actions in the Action Keyword class
//method variable contain all the method and method.length returns the total number of methods
for(int i = 0;i < method.length;i++){
//This is now comparing the method name with the ActionKeyword value got from excel
if(method[i].getName().equals(sActionKeyword)){
//In case of match found, it will execute the matched method
method[i].invoke(actionKeywords);
//Once any method is executed, this break statement will take the flow outside of for loop
break;
}
}
}
}

seleniumbeginer Default Answered on November 22, 2015.
Add Comment

Your Answer

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