Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

checking cell is null or not

807597Aug 31 2005 — edited Aug 31 2005
Hi ,
Iam using poi to read excel sheet. Iam reading line by line of excel sheet using HssfUserModel.
Here is my code
int numberOfRows = sheet.getLastRowNum();
for (int i = 1; i <= numberOfRows; i++)
 {

  HSSFRow row = sheet.getRow(i);
//  check whether row is null or not
  if (row != null)
   {
    int numberOfCells = row.getLastCellNum();
				
     for(int j=0;j <= numberOfCells;j++)
     {
         HSSFCell cell = row.getCell((short)j);
         short cellNumber = cell.getCellNum();
	 //check whether cell is null or not
          if(cell!=null)
          {
            if(cellNumber ==  myTradeConstants.scripCode_column_Number)
              {
               cell =row.getCell(myTradeConstants.scripCode_column_Number);
               scripCode =cell.getStringCellValue();
               System.out.println("scripCode:"+scripCode);
             }
	 }
        else
         {
              System.out.println("nocellValue");
              break;
         }
      } 
  }
else 
{
   System.out.println("rowBreak");
   break;
}
My Excel sheet is also having so many number of rows. But it is displaying only first row of the excel sheet. n displaying "nullpointerException".
why iam getting nullPointer Exception.

I want to check whether a cell is having data or not.
can anybody guide me in right dircection.

regards,
ramu.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 28 2005
Added on Aug 31 2005
4 comments
443 views