Created attachment 26994 [details] The used Excel-File with Exception Hi , I use the liblary poi-3.7-20101029.jar. By reading an excel-File in the function cell.getCellType() throw null exception.
The exception is thrown by reading the attachment file in the row number 1.
Are you sure that your variable cell isn't null? Can you please post the code required to trigger your problem?
Cell cell = sheet.getRow(getIntValueRowID(rowID)).getCell(getIntValue(colID)); // System.out.println("Type " + cell.getCellType()); //System.out.println( cell.getCellStyle()); switch(cell.getCellType()) { case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_STRING: value = cell.getStringCellValue(); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC: if(org.apache.poi.hssf.usermodel.HSSFDateUtil.isCellDateFormatted(cell)) { value = cell.getDateCellValue().toString(); } else { value = cell.getNumericCellValue() +""; } break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BOOLEAN: value = Boolean.toString(cell.getBooleanCellValue()); break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_ERROR: value = null; break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BLANK: value=null; break; case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_FORMULA: //Formula cells have the formula string, as well as the formula result, which can be numeric or string. try{ // get the formula result as string value = cell.getStringCellValue(); } catch (Exception e) { //wenn eine Exception ausfällt, dann gib es als ein Number wert zurück value = Double.toString((cell.getNumericCellValue())); } break; default: value = null; break; } String errorMessage = null; if (checkEmpty && (value == null || value.length() == 0)) { errorMessage = "Wert in Feld: " + colID + rowID + " ist leer!"; } else if (datatype != null) { if (!checkDataType(value, datatype)) { // vorgegeben typen: String, numerische datens errorMessage = TEXT_UNERWARTET + colID + rowID + ", Arbeitsblatt: " + sheetName + " Erwartet war: "+ datatype; } } // Fehler Ausgeben falls vorhanden if (errorMessage != null) { handleError(errorMessage); } }catch(Exception e){ //throw new ContentAccessException("Zugriff auf Zelle " + colID + rowID + " nicht möglich." + e.getMessage()); String message = "Zugriff auf Zelle " + colID + rowID + " nicht möglich."+ e.getMessage(); reportError(message); }
i get the exception, if the cell is cell.getCellType(). i think, you have right.
You don't appear to be checking that a cell isn't null after retrieving it, but before asking for the type. Cells may not be there, if they're not in the file, unless you have set a MissingCellPolicy Check the cell is there before using it and you'll be fine