Getting null pointer exception while trying to write in xlsx file
<p>I am getting following error while writing values to last column of the row.
The last cell has to be created new.</p>

<p><code>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)</code></p>

<p>My Code is</p>

<pre><code>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();
        }
    } 
}
</code></pre>

<p>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.</p>

<p>When i try to do this I am getting NullPointer Exception.</p>

<p>Actually I am getting this error in this line </p>

<blockquote>
  <p>cell.setCellValue(value);</p>
</blockquote>