NullPointerException raise while trying update a excel cell using Apache POI. Particular cell that I want to update has some value but I can't update due to exception.
String excelFileName = "D:\\TempLocation\\Marks.xlsx";//name of excel file
String sheetName = "Sheet1";//name of sheet
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.getSheet(sheetName) ;
System.out.println(regNo+ " " + cellNo);
Cell cellToUpdate = sheet.getRow(0).getCell(0);
cellToUpdate.setCellValue(mark);
FileOutputStream fileOut = new FileOutputStream(excelFileName);
//write this workbook to an Outputstream.
wb.write(fileOut);
fileOut.flush();
fileOut.close();
this is my code. Exception raised at this line:
Cell cellToUpdate = sheet.getRow(0).getCell(0);