title: Trying to get data from excel then store it inside array and later print it
body: <p>I am trying to read data from an excel file. When i run the below code it runs without any error but won't give any data. When i checked the code i found that the global variable rownum is not initializing and giving the default value which is 0. But inside the getData(int i) method the rownum is giving a value of 14. 
  I am trying to get all string data available in excel file by using getData(int i) method and later trying to store them inside data[] array. Again inside the setData method i am trying to copy all item stored inside the data[] array to a string value. 
  Can anyone please help. I am new to java.
     package com.selenium;</p>
  
  <pre><code>import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  import org.apache.poi.ss.usermodel.Row;
  import org.apache.poi.ss.usermodel.Sheet;
  import org.apache.poi.ss.usermodel.Workbook;
  import org.apache.poi.ss.usermodel.WorkbookFactory;
  
  
  @SuppressWarnings("unused")
  public class DataFromExcel {
    String[] data = new String[15];
    static int rownum;
  
   public String[] getData(int i) throws InvalidFormatException, IOException{
     File file = new File("C:\\Users\\Admin\\Desktop\\ScreenShot\\Excel.xls");
     FileInputStream input = new FileInputStream(file);
     Workbook excel = WorkbookFactory.create(input);
     Sheet sheet = excel.getSheet("Data");
     rownum = sheet.getLastRowNum();
     System.out.println(rownum);
  
  
       for(int j=1;j&lt;=rownum;j++){
           Row row = sheet.getRow(rownum);
           while(row != null){
           if(row.getCell(j) != null){
           String cell = row.getCell(j).getStringCellValue();
           while(cell != null){
               data[j]=cell;
               System.out.println(data[1]);
           }//while cell
          }//if row 
        }//for  
       }//row while
      return data;
     }//getData 
    public String setData(int i){
        String value = null;
        for(i=1; i&lt;=data.length;i++){
            value =data[i];
        }//for setData
      return value;
    }//setData
  
   public static void main(String[] args) throws InvalidFormatException, IOException{
      DataFromExcel get = new DataFromExcel();
      System.out.println(rownum);
      get.getData(1);
      if(get.data != null){
      System.out.println(get.setData(1));}
   }//main
  }// DataFromExcel
  </code></pre>