I would like to write to a cell on sheet 2, but the operation errors and I get this message :
Exception in thread "main" java.lang.NullPointerException
at Testnextsheet.Testnextsheet.main(Testnextsheet.java:43)
public static void main(String[] args) throws IOException{
try{
FileInputStream files = new FileInputStream(new File("d:\\Materi\\Selenium\\Projects\\Excel\\Book1.xlsx"));
XSSFWorkbook workbook = new XSSFWorkbook(files);
//----Sheet 1-------------------------------------//
XSSFSheet sheet1 = workbook.getSheet("Sheet1");
//---sheet 2--------------------------------------//
XSSFSheet sheet2 = workbook.getSheet("Sheet2");
//-----------write text to sheet 2------------------------//
sheet2.getRow(3).getCell(2).setCellValue("Test");
FileOutputStream fout= new FileOutputStream(new File("d:\\Materi\\Selenium\\Projects\\Excel\\Book1.xlsx"));
workbook.write(fout);
workbook.close();
files.close();
}
catch(FileNotFoundException fnfe){
fnfe.printStackTrace();
}catch(IOException ioe){
ioe.printStackTrace();
}
}