Bug 51193 - cell.getCellType() throws the null exception
Summary: cell.getCellType() throws the null exception
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: POI Overall (show other bugs)
Version: 3.7-FINAL
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-13 08:48 UTC by mai00ihf
Modified: 2011-05-26 10:54 UTC (History)
0 users



Attachments
The used Excel-File with Exception (13.50 KB, application/vnd.ms-excel)
2011-05-13 08:48 UTC, mai00ihf
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mai00ihf 2011-05-13 08:48:36 UTC
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.
Comment 1 mai00ihf 2011-05-13 09:06:23 UTC
The exception is thrown by reading the attachment file in the row number 1.
Comment 2 Nick Burch 2011-05-13 09:09:28 UTC
Are you sure that your variable cell isn't null?

Can you please post the code required to trigger your problem?
Comment 3 mai00ihf 2011-05-26 09:09:18 UTC
		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);
			}
Comment 4 mai00ihf 2011-05-26 09:13:24 UTC
i get the exception, if the cell is cell.getCellType(). i think,
you have right.
Comment 5 Nick Burch 2011-05-26 10:54:27 UTC
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