First of all, I apologize for my bad english, it's not my primary language. I'm having a problem with my code when it's reading an excel file (xlsx). The first time I used my code it works perfectly, but now I can't use it. The excel content is printed on the console, but next to it there is a NullPointerException that is caused by the for loop marked with the (-->>>). If anyone can help me, I would be very thankful, this code has given me several headaches.
package modleerjava;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class leerExcel {
public void readExcel(String rutaFile,String nombreFile, String sheetName )
throws IOException {
File file = new File ("C:/Users/Pablo/Desktop/prueba.xlsx");
FileInputStream inputStream = new FileInputStream(file);
XSSFWorkbook excelWorkbook ;
excelWorkbook = new XSSFWorkbook(inputStream);
Sheet excelSheet = excelWorkbook.getSheet(sheetName);
int filasCount = excelSheet.getLastRowNum()-excelSheet.getFirstRowNum();
for (int i=0; i< filasCount+1 ; i++) {
Row filas;
filas = excelSheet.getRow(i);
-->>> for (int j=0 ; j < filas.getLastCellNum(); j++) {
System.out.print(filas.getCell(j).getStringCellValue()+"|| ");
}
System.out.println();
}
}
}