You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by Amith <am...@gmail.com> on 2011/09/22 09:04:51 UTC

Null pointer Exception while reading xls empty row

Hello Friend..........
              
               Am trying to read an excell sheet using apache poi and i got
all the values from excell sheet when i added an  extra row  between the
content  [          IN Brief:-   I have 19 row in ma excell sheet and all of
them contains at least 1 data when i added an empty row  in 13 th position
(Manually)      ]    IT creates null pointer exception and i cannot read the
rest of rows i tried to delete the empty row from excell sheet by using the
following code


FileInputStream fs =new FileInputStream(filename);
		 					//sstrec = SSTRecord;
		 					HSSFWorkbook wb = new HSSFWorkbook(fs);
		 					int j=i+1;
		 					HSSFSheet sheet = wb.getSheetAt(0);
						    //rows  = sheet.getPhysicalNumberOfRows();
						    int firstRow=sheet.getFirstRowNum();
						    rows=sheet.getLastRowNum();
						    System.out.println(rows);
						    
						    
						    boolean stop = false;
				            boolean nonBlankRowFound;
				            short c;
				            HSSFRow lastRow = null;
				            HSSFCell cell = null;

				            while (stop == false) 
				            {
				            	
				                nonBlankRowFound = false;
				                lastRow = sheet.getRow(12);
				                for (c = lastRow.getFirstCellNum(); c <=
lastRow.getLastCellNum(); c++) {
				                     cell = lastRow.getCell(c);
				                    if (cell != null && lastRow.getCell(c).getCellType()
!= HSSFCell.CELL_TYPE_BLANK) {
				                        nonBlankRowFound = true;
				                    }
				                }
				                if (nonBlankRowFound == true) {
				                    stop = true;
				                } else {
				                    sheet.removeRow(lastRow);
				                }
				            }


but results the same nullpointer exception 


      please.............. help me to sort out this issuee thnk
you..........

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Null-pointer-Exception-while-reading-xls-empty-row-tp4829181p4829181.html
Sent from the POI - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: Null pointer Exception while reading xls empty row

Posted by Helfi <st...@t-online.de>.
for (Row row : sheet) {
	// Skip empty rows
	if (row == null) {
		continue;
	}

        //Iterate over all cells
	for (Cell cell : row) {
               // Skip empty cells
	       if (row == null) {
		     continue;
	       }
		...			
	}
}

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Null-pointer-Exception-while-reading-xls-empty-row-tp4829181p4829268.html
Sent from the POI - Dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org