RE: Null Pointer exception in Keyword Driven Framework

hi Lakshay & Team,

Thanks for this wonderful site, Like me, you are helping lot of people out there. God bless you all.

I am getting same error, after debugging , error throws in execute_Actions() method, as you told sActionKeyword, it has a value openBrowser but when it enters the execute_Action method Method method.length will be null.

This the code

 

package executionEngine;
import java.lang.reflect.Method;

import config.ActionKeywords;

import utility.ExcelUtils;
public class DriverScript {
public static ActionKeywords actionKeywords;

public static String sActionKeyword;

public static Method method[];
public DriverScript() throws NoSuchMethodException, SecurityException{

actionKeywords = new ActionKeywords();

method = actionKeywords.getClass().getMethods();

}

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

String sPath = “..\\src\\dataEngine\\DataEngine.xlsx”;

ExcelUtils.setExcelFile(sPath, “Test Steps”);

for (int iRow=1; iRow<=9; iRow++){

sActionKeyword = ExcelUtils.getCellData(iRow, 3);

execute_Actions();

}

}
private static void execute_Actions() throws Exception {

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

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

method[i].invoke(actionKeywords);

break;

}

}

}

}
Add Comment
5 Answers

The NullReferenceException is designed as a valid runtime condition that can be thrown and caught in normal program flow. It indicates that you are trying to access member fields, or function types, on an object reference that points to null. That means the reference to an Object which is not initialized.

Johnson

Default Answered on October 5, 2016.
Add Comment

Your Answer

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