title: Driver Null pointer exception while using the driver from Test class in Page class
body: <p>I have two classes a Base class and Test class</p>
  <p>Base class:</p>
  <pre><code>public class Base {
      
      public static WebDriver driver;
  
      public void browser() {
  
      System.setProperty(&quot;webdriver.chrome.driver&quot;, 
       &quot;C:\\Users\\admin\\Desktop\\Selenium\\chromedriver.exe&quot;);
  
      driver  = new ChromeDriver();
      
      driver.manage().window().maximize();
      
      }
  
  </code></pre>
  <p>And, I am extending my Test  classes to the Baseclass to use the driver reference,</p>
  <pre><code>public class FacebookTestCase extends Base{
      
      
      public static void main(String[] args ) {
              
          driver.get(&quot;www.facebook.com&quot;); 
  
          driver.findElement(By.id(&quot;email&quot;)).sendKeys(&quot;tetst@test.in&quot;);
  
          driver.findElement(By.id(&quot;pass&quot;)).sendKeys(&quot;test&quot;);
          driver.findElement(By.name(&quot;login&quot;)).click();
          
      }
  
  }
  
  </code></pre>
  <p>But I am getting Null pointer exception when I run the Test class.</p>
  <p>Exception in thread &quot;main&quot; java.lang.NullPointerException
  at grid.practice.FacebookTestCase.main(FacebookTestCase.java:12)</p>
  <p><em><strong><strong>EDITED</strong></strong></em></p>
  <p>I have another query,</p>
  <p>Now I am separating my Test class and Page class and I am calling my page class methods from my test class. I am
  creating an object of the page class and calling the methods. But I get null pointer exception in the Page class when I pass the
  driver to the constructor of the page class.</p>
  <p>Test class:</p>
  <pre><code>public class FacebookTestCase extends Base{
      
      
      public static void main(String[] args ) {
              
      driverInitialization();
      FacebookElements fb = new FacebookElements(driver);
      fb.login();
          
          
      }
  </code></pre>
  <p>Page class:</p>
  <pre><code>public class FacebookElements{
  
      WebDriver driver;
  
      public FacebookElements(WebDriver driver) {
      this.driver = driver;
  
      }
      
      
      public void login() {
  
      driver.findElement(By.id(&quot;username&quot;)).sendKeys(&quot;test&quot;);
      driver.findElement(By.id(&quot;password&quot;)).sendKeys(&quot;test&quot;);
      }
  
  }
  </code></pre>