title: Null Pointer Exception while using Reflection
body: <p>I'm following a tutorial for Selenium - Keyword Driven Framework <a href="http://toolsqa.com/selenium-webdriver/keyword-driven-framework/java-reflection-class/" rel="nofollow noreferrer">here</a>. I'm not very familiar with the the Reflection API. (I'm a beginner to Java as well)</p>
  
  <p>When I execute my main class, I'm receiving a Null Pointer Exception. I'm not sure what I'm doing wrong. Might be a silly mistake. Please help me understand what I'm missing here. 
  (Also, if someone can guide me where I can learn better about Keyword Driven Framework and the Reflection API from a beginner's standpoint, that would be very helpful.)</p>
  
  <p><strong>DriverScript:</strong></p>
  
  <pre><code>package testdev;
  
  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 = "C://Users//testusr//workspace//src//datasource//datasource.xlsx";
      ExcelUtils.setExcelFile(sPath, "sheet");
  
      for(int i=1; i&lt;=7; i++){
          sActionKeyword = ExcelUtils.getCellData(i, 3);
          execute_Actions();
      }
  }
  
  private static void execute_Actions() throws Exception{
  
      for(int j=0;j &lt; method.length;j++){
          if(method[j].getName().equals(sActionKeyword)){
              method[j].invoke(actionKeywords);
              break;
          }
      }
  
  }
  }
  </code></pre>
  
  <p><strong>ActionKeywords:</strong></p>
  
  <pre><code>package config;
  
  import java.util.concurrent.TimeUnit;
  import org.openqa.selenium.By;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.chrome.ChromeDriver;
  
  public class ActionKeywords {
  
  public static WebDriver driver;
  
  public static void openbrowser(){
      System.setProperty("webdriver.chrome.driver", "G:\\Usr\\MAC\\Se\\chromedriver.exe");
      driver = new ChromeDriver();
  }
  
  public static void navigate(){
      driver.get("URL");
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      driver.manage().window().maximize();
  }
  
  public static void enter_credentials(){
      driver.findElement(By.id("login-form-username")).sendKeys("username");
      driver.findElement(By.id("login-form-password")).sendKeys("pswd");
  }
  
  public static void click_login(){
      driver.findElement(By.id("login")).click();
  }
  
  public static void wait_for(){
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
  }
  
  public static void click_logout() throws InterruptedException{
      driver.findElement(By.id("header-details-user-fullname")).click();
      Thread.sleep(30);
      driver.findElement(By.id("log_out")).click();
  }
  
  public static void closebrowser(){
      driver.quit();
  }
  
  }
  </code></pre>
  
  <p><strong>ExcelUtils:</strong></p>
  
  <pre><code>package utility;
  
  import java.io.FileInputStream;
  import org.apache.poi.xssf.usermodel.XSSFCell;
  import org.apache.poi.xssf.usermodel.XSSFSheet;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  
  public class ExcelUtils {
  
  public static XSSFWorkbook ExcelWBook;
  public static XSSFSheet ExcelWSheet;
  public static XSSFCell Cell;
  public static FileInputStream ExcelFile;
  
  public static void setExcelFile (String Path, String SheetName) throws Exception{
      FileInputStream ExcelFile = new FileInputStream(Path);
      ExcelWBook = new XSSFWorkbook(ExcelFile);
      ExcelWSheet = ExcelWBook.getSheetAt(0);
  }
  
  public static String getCellData (int rowNum, int colNum) {
      String CellData ="";
      Cell = ExcelWSheet.getRow(rowNum).getCell(colNum);
      CellData= Cell.getStringCellValue();        
      return CellData;
  }
  }
  </code></pre>
  
  <p><strong>Exception:</strong></p>
  
  <pre><code>java.lang.NullPointerException
  at testdev.DriverScript.execute_Actions(DriverScript.java:37)
  at testdev.DriverScript.main(DriverScript.java:28)
  </code></pre>
  
  <p><strong>Excel sheet :</strong> </p>
  
  <p><a href="https://i.stack.imgur.com/Tizww.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Tizww.jpg" alt="datasource.xlsx"></a></p>