If the exception is raised by this line:
key = "" +sht.getRow(0).getCell(j).getNumericCellValue();
It means that the type of sht.getRow(0).getCell(j)
is not numeric.
Use the same variable in your if clause
and in the if block
, or it will be a never ending source of bugs.
Row row = sht.getRow(0);
Cell cell = row.getCell(j);
...
String key = null;
else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
key = "" +cell.getNumericCellValue();
}
So now 2 cases
- If cell is of type NUMERIC then it will work and you will have a key.
- If cell is NOT of type NUMERIC then it will still work (not crash) but you will have a null key.
Also I would be curious to see what output you get if you add the following print statements before your if:
System.out.println("Cell.CELL_TYPE_NUMERIC: "+Cell.CELL_TYPE_NUMERIC);
System.out.println("rw.getCell(j).getCellType(): "+rw.getCell(j).getCellType());
System.out.println("sht.getRow(0).getCell(j).getCellType(): "+sht.getRow(0).getCell(j).getCellType());
I expect them to not be all the same.