title: i am getting a java.lang.NullPointerException while executing the testng script
body: <p>while running the code i am getting this java.lang.NullPointerException in chrome, i have extended the main login class to another and its showing this exception. i have extended the same main class to another diff class and its successfully running but only this class is showing error.</p>
  <p>here is the code</p>
  <p>//login page
  public class admin_login {</p>
  <pre><code>//public static void main(String args[]) throws InterruptedException{
  WebDriver driver;
  @Test
  public void login() throws InterruptedException{    
      System.setProperty(&quot;webdriver.chrome.driver&quot;,&quot;E:\\Automation\\jarfiles2\\chromedriver_win32_new\\chromedriver.exe&quot;);
      driver = new ChromeDriver();
      
      driver.get(&quot;http://localhost/Login&quot;);
      driver.manage().window().maximize();
      Thread.sleep(2000);
      //driver.close();
  
      driver.findElement(By.id(&quot;UserName&quot;)).sendKeys(&quot;admin&quot;);
      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
      
      driver.findElement(By.id(&quot;Password&quot;)).sendKeys(&quot;adminadmin&quot;);
      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
      
      driver.findElement(By.cssSelector(&quot;input.btn&quot;)).click();
  }
  </code></pre>
  <p>}</p>
  <p>//Userclass</p>
  <p>public class User extends admin_login{</p>
  <pre><code>@Test
  public void user() throws InterruptedException{
   //master dropdown  
  //driver.findElement(By.xpath(&quot;//*[@id='topNavbarCollapse']/ul[1]/li[1]/a&quot;)).click();
      try{
          driver.findElement(By.xpath(&quot;//*[@id='topNavbarCollapse']/ul[1]/li[1]/a&quot;)).click();
          
      }
      catch(java.lang.NullPointerException n){
          //System.out.println(&quot;exception handaled&quot;);
          System.out.println(n.getMessage());
      }
      finally{
          driver.findElement(By.xpath(&quot;//*[@id='topNavbarCollapse']/ul[1]/li[1]/a&quot;)).click();
      }
  </code></pre>
  <p>i have tried to get normally and then via try catch also but its still showing the same exception and test failed</p>
  <p>stack trace</p>
  <pre><code>java.lang.NullPointerException
      at Finlogin.User.user(User.java:19)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
      at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
      at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
      at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
      at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
      at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
      at org.testng.TestRunner.privateRun(TestRunner.java:648)
      at org.testng.TestRunner.run(TestRunner.java:505)
      at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
      at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
      at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
      at org.testng.SuiteRunner.run(SuiteRunner.java:364)
      at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
      at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
      at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
      at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
      at org.testng.TestNG.runSuites(TestNG.java:1049)
      at org.testng.TestNG.run(TestNG.java:1017)
      at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
      at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
      at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
  </code></pre>