title: Getting last row value using apache poi
body: <p>Getting java.lang.NullPointerException when i try to get the value of the 
  last row in a excel sheet using getLastRowNum() function.</p>
  
  <pre><code>import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.io.IOException;   
  import org.apache.poi.xssf.usermodel.XSSFSheet;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  
  public class Excel{
  public static File file;
  public static FileInputStream input;
  public static FileOutputStream output;
  public static HSSFWorkbook book;     
  public static HSSFSheet sheet;
  public static int value;
  public Excel(String path) {
  
  
      try {
          file= new File(path);//creating file//
          input=new FileInputStream(file);
          book=new HSSFWorkbook(input);           
          sheet=book.getSheetAt(0);                
          output=new FileOutputStream(file);          
      }
      catch(Exception e) {
          e.getMessage();
      }
          }
  public static void readData() {
      int value =sheet.getLastRowNum();//trying to get the last row value//
      System.out.println(value);
  
  }
  }
  </code></pre>
  
  <p>Driver class:</p>
  
  <pre><code>      public class ExcelTest {
        public static void main(String[] args) {
        Excel excel = new Excel("C:/Users/HOME/Desktop/Sample.xlsx");
        Excel.readData();     
  }
  } 
  </code></pre>
  
  <p>Please help on the issue.</p>