title: getting NullPointerException for inline code. I have defined the WebDriver globally, call browser method is working fine What i am doing wrong here
body: <pre><code>public class Test{
      static WebDriver driver;
      public static void main(String[] arg) throws IOException, InterruptedException {
          Test2();
      }
  
      public static void CallBrowserChrome() {
          try {
              System.setProperty(&quot;webdriver.chrome.driver&quot;, &quot;G:\\Chrome\\chromedriver.exe&quot;);
              WebDriver driver = new ChromeDriver();
              driver.get(&quot;https://google.com&quot;);
              
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
      public static void Test2() throws IOException, InterruptedException {
          CallBrowserChrome();
  
          FileInputStream fis = new FileInputStream(&quot;G:\\Book1.xlsx&quot;);
          XSSFWorkbook wb = new XSSFWorkbook(fis);
          XSSFSheet sheet = wb.getSheetAt(0);
          int rows = sheet.getLastRowNum();
          System.out.println(rows);
          for (int i = 1; i &lt;= rows; i++) {
              String value = sheet.getRow(i).getCell(0).getStringCellValue();
              System.out.println(value);
              **driver.findElement(By.xpath(&quot;//*[@id='js-main-container']&quot;))
                      .sendKeys(value);**
          }
          }
  }
  </code></pre>
  <p>//The Error is at this line Highlighted(driver in 2nd Class); I have tried giving the WebDriver inside the body of the method but that also does not work</p>
  <pre><code>  [1]: https://i.stack.imgur.com/0GzeA.png
  </code></pre>