0

I am getting following error while writing values to last column of the row. The last cell has to be created new.

java.lang.NullPointerException at com.dnb.util.WriteExcel.writeXLSXFile(WriteExcel.java:37) at com.dnb.reducer.ComparisionReducer.reduce(ComparisionReducer.java:47) at com.dnb.reducer.ComparisionReducer.reduce(ComparisionReducer.java:1) at org.apache.hadoop.mapreduce.Reducer.run(Reducer.java:176) at org.apache.hadoop.mapred.ReduceTask.runNewReducer(ReduceTask.java:566) at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:408) at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:216)

My Code is

public class WriteExcel {

    public void writeXLSXFile(int row, String value) throws IOException {
        try {
             FileInputStream file = new FileInputStream(new File("C:\\Users\\582092\\Desktop\\Inputs\\Book2.xlsx"));
             XSSFWorkbook workbook = new XSSFWorkbook(file);
             XSSFSheet sheet = workbook.getSheetAt(0);
             Row r = sheet.getRow(row);
             int col = sheet.getRow(row).getPhysicalNumberOfCells();
             Cell cell = r.createCell(col);
             cell.setCellValue(value);
             file.close();
             FileOutputStream outFile =new FileOutputStream(new File("C:\\Users\\582092\\Desktop\\Inputs\\Book1.xlsx"));
             workbook.write(outFile);
             outFile.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } 
}

My Question is i have a excel file with 12 columns. I am going to do some validation with this 12 columns and i want to write the result of this validation in 13th column of each row.

When i try to do this I am getting NullPointer Exception.

Actually I am getting this error in this line

cell.setCellValue(value);

Gowtham
  • 53
  • 3
  • 10

0 Answers0