I am trying to create a program which reads the red value's from an image and stores the data into excel using Apache POI so i can create a histogram with it. However i'm getting a nullPointerException
on the array i'm storing the data in when i try to pass the information to excel.
The values in the array are taken from a 2d array which stores all the rgb values of the image. I have checked the array and the values are getting stored within it.
Do any of you guys know what would be causing this error?
The array is declared as:
static int[] redArray = new int[255];
And here is the code i am using to store the data into excel. The error occurs at cell.setCellValue(redArray[y]);
public static void chart() throws IOException {
FileInputStream file = new FileInputStream(new File("chart.xlsx"));
// Finds the workbook instance for XLSX file
XSSFWorkbook myWorkBook = new XSSFWorkbook(file);
// Return first sheet from the XLSX workbook
XSSFSheet mySheet = myWorkBook.getSheetAt(0);
// HSSFWorkbook workbook = new HSSFWorkbook(file);
// HSSFSheet sheet = workbook.getSheetAt(0);
// Sheet sheet=(Sheet) workbook.getSheetAt(0);
Cell cell = null;
// Update the value of cell
for (int i = 1, y = 0; i < 255 && y < 255; i++, y++) {
cell = mySheet.getRow(1).getCell(i);
cell.setCellValue(redArray[y]);
System.out.println("asdasd");
}
file.close();
FileOutputStream outFile = new FileOutputStream(
new File("update2.xlsx"));
myWorkBook.write(outFile);
outFile.close();
myWorkBook.close();
}
Thanks for the help.