I'm having a problem with writing in a excel file. I'm using Apache POI to write on the excel.
My code is:
private void EscreverExcel(String Nome) throws FileNotFoundException, IOException{
File src = new File("D:\\Work\\Fortune\\DadosCliente.xlsx");
FileInputStream fist = new FileInputStream(src);
XSSFWorkbook wb = new XSSFWorkbook(fist);
XSSFSheet sheet = wb.getSheetAt(0);
sheet.getRow(0).createCell(2).setCellValue(Nome);
FileOutputStream fos = new FileOutputStream(src);
wb.write(fos);
wb.close();
}
public static void main(String[] args) throws IOException{
Excel ex = new Excel();
ex.EscreverExcel("Mário");
}
and when i run the program they give me this:
Exception in thread "main" java.lang.NullPointerException
at fortunewheel.Excel.EscreverExcel(Excel.java:79)
at fortunewheel.Excel.main(Excel.java:87)
What i did wrong? can u help me out?