title: Getting "Null pointer exception" at the time of executing maven project using selenium webdriver
body: <p>When my code is executing first it execute the <code>LoginTest.Java</code> class after that it goes to the <code>Main.Java</code> but in these I get the null pointer exception, its not reading get the driver in method.
  Can anyone please help me to resolve, I am beginner in this.</p>
  
  <p>Thanks in advance..!!</p>
  
  <p><strong>LoginTest.Java class</strong>:</p>
  
  <pre><code>public class LoginTest {
      private static final String ADDRESS_TO_TEST = "http://www.gmail.com";
  
      private WebDriver driver;
      Main Login;
      HomePage homePage;
  
      @BeforeTest
      public void setUp() {
  
          FirefoxDriver driver = new FirefoxDriver();
          driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
          driver.get(ADDRESS_TO_TEST);
  
      }
  
      @Test(priority = 0)
      public void testLoginPageAppear() {
  
          // Create Login Page object
          Login = new Main(driver);
          System.out.println("Login--&gt;" + Login);
          Login.loginToGmail("abc@gmail.com", "abc");
          homePage = new HomePage(driver);
          // Verify home page
          Assert.assertTrue(homePage.getHOmePageEmailAddress().toLowerCase()
                  .contains("Google Account: abc@gmail.com"));
      }
  }
  </code></pre>
  
  <p><strong>Main.Java Class:</strong></p>
  
  <pre><code>package GmailLogin;
  
  import org.openqa.selenium.By;
  import org.openqa.selenium.WebDriver;
  
  public class Main {
  
      /*
       * Reference
       * URL:http://www.guru99.com/page-object-model-pom-page-factory-in-
       * selenium-ultimate-guide.html
       */
  
      WebDriver driver;
  
      By email = By.id("Email");
      By nextButton = By.id("next");
      By password = By.id("Passwd");
      By signInButton = By.id("signIn");
  
      public Main(WebDriver driver) {
          System.out.println("Driver---&gt;" + driver);
          this.driver = driver;
      }
  
      public void setEmailAddress(String strEmailAddress) {
          driver.findElement(email).sendKeys(strEmailAddress);
  
      }
  
      public void clickNextButton() {
          driver.findElement(nextButton).click();
      }
  
      public void setPassword(String strPassword) {
          driver.findElement(password).sendKeys(strPassword);
      }
  
      public void clickSignInButton() {
          driver.findElement(signInButton).click();
      }
  
      public void loginToGmail(String strEmailAddress, String strPassword) {
  
          System.out.println("Email--&gt;" + strEmailAddress);
          System.out.println("Password--&gt;" + strPassword);
          this.setEmailAddress(strEmailAddress);
          this.clickNextButton();
          this.setPassword(strPassword);
          this.clickSignInButton();
      }
  }
  </code></pre>
  
  <p><strong>Null pointer exception:</strong></p>
  
  <pre><code>-------------------------------------------------------
   T E S T S
  -------------------------------------------------------
  Running TestSuite
  Driver---&gt;null
  Login--&gt;GmailLogin.Main@5940ce27
  Email--&gt;abc@gmail.com
  Password--&gt;abc
  Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 21.016 sec &lt;&lt;&lt; FAILURE! - in TestSuite
  testLoginPageAppear(GmailLogin.LoginTest)  Time elapsed: 0.047 sec  &lt;&lt;&lt; FAILURE!
  java.lang.NullPointerException
      at GmailLogin.LoginTest.testLoginPageAppear(LoginTest.java:47)
  </code></pre>