title: Apache POI excel file read same code giving different results for two different sheets
body: <p>I am trying data driven testing with two different sheets in one single excel sheet. But what I observed is same code gave two different results when I tried executing a two different test cases. It was strange. One sheet data got properly processed but for another, same code gave Null pointer exception on a particular line. Below is the code.</p>
  <pre><code>@DataProvider(name=&quot;testdataforinvalidvalues&quot;)
      public static Object[][] readexcelretobjinvalidval() throws Exception {
          System.out.println(&quot;Data provider called&quot;);
          HSSFWorkbook workbook = assignworkbook();
          HSSFSheet s = workbook.getSheetAt(2);
          String sp = s.getSheetName();
          System.out.println(sp);
          HSSFRow row = s.getRow(0);
          int rownum=s.getPhysicalNumberOfRows();
          int colnum=row.getLastCellNum();
          System.out.println(rownum);
          System.out.println(colnum);
  
          //System.out.println(rownum);
          //System.out.println(colnum);
          Object data[][] = new Object[rownum][colnum];
          List&lt;Object&gt; l = new ArrayList&lt;Object&gt;();
          for(int i=0;i&lt;rownum-1;i++) {
              row = s.getRow(i+1);
              for(int j=0;j&lt;colnum;j++) {
                  **HSSFCell c  = row.getCell(j);**
                  //l.add(c.getStringCellValue());
                  data[i][j]=c.getStringCellValue();
              }
          }
  
          return data;
  </code></pre>
  <p>The line in the code HSSFCell c  = row.getCell(j); which I tried to show in bold just below for loop is throwing null pointer exception.</p>
  <p>The test case which I tried to run is as follows.</p>
  <pre><code>@Test(dataProvider=&quot;testdataforinvalidvalues&quot;,dataProviderClass=Excel_Util.class)
      public void testsignupdatafieldsinvval(String email, String password) {
  
          Syncutil.Implicitwait();
          System.out.println(&quot;Test case called&quot;);
          try {
  
              getdriver().get(&quot;https://www.&quot;+csvreaderutil.csvread().get(0).toString()+&quot;/&quot;);
              Marathishd marathishdpage = PageFactory.initElements(getdriver(), Marathishd.class);
              Signuppagemarathishd signup = marathishdpage.letsbeginclick();
              signup.emailid.sendKeys(email);
              signup.password.sendKeys(password);
              Syncutil.Explicitwait(signup.invalidemailerrormessage);
              Syncutil.Explicitwait(signup.invalidpassworderrormessage);
              Syncutil.Explicitwait(signup.enteremailmessage);
              Assert.assertEquals(signup.enteremailmessage.getText(), &quot;Enter your Email ID&quot;);
              Assert.assertEquals(signup.invalidemailerrormessage.getText(), &quot;Please enter correct Email&quot;);
              Assert.assertEquals(signup.invalidpassworderrormessage.getText(), &quot;Please enter 4 to 20 characters password without any spaces&quot;);
              
  
  
          }catch(Exception e) {System.out.println(&quot;Exception&quot;);}
      }
  </code></pre>
  <p>I am confused why the data provider code behaved differently for two different sheets.Can anyone please help me ?</p>