Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

Hi,
I am reading an Excel file but i am getting “Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException” Error.

I have attached demo file . My First cell is having data and other cells are blank for first 2 rows,

Can you suggest me the best way to handle this exception as my File Structure is same.

Thanks.

Hi,


Could you give us your sample code to reproduce the issue on our end.
I just tried to read and write (Save As) your file with the attached version and it works fine.

Sample code:
Workbook book = new Workbook();
book.open(“Demo.xls”);
book.save(“outDemo.xls”);
Kindly try the attached version, if you still find the issue paste your sample code here, we will check your issue soon.

Thank you.

Hi,
This is the Code that i am Using for Reading the File

Code:

Workbook workbook = new Workbook();
FileInputStream fstream = new FileInputStream(Demo.xls);
workbook.open(fstream, FileFormatType.EXCEL97TO2003);
Worksheet worksheet = workbook.getWorksheets().getSheet(0);
Cells cells = worksheet.getCells();
System.out.print(workbook.getWorksheets().getActiveSheet().getName());
int num=cells.getMaxRow();
int num1=cells.getMaxColumn();
System.out.print(num);
System.out.print(num1);
for (int n=1;n<num;n++)
{ for(int nColIndex =0;nColIndex<=Last;nColIndex++)
{
System.out.println(cells.getCell( n,nColIndex).getValue());
Cell cell=cells.getCell(n,nColIndex);
}
}
workbook.save(“C:\OutPut.xls”,FileFormatType.EXCEL97TO2003);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}



Hi,


Please try the latest fix/version that I attached in my previous reply. I have tested, it works fine with your code.

Thank you.

Thanks it is working Fine.

Hi,


Good to know that your issue is resolved now.

Thank you and have a nice day!