I am a beginner of java. I wrote this code. When I run it in eclipse, I get an error: java lang null point exception. It does not tell me which line I have wrong code. Please advise on how to fix it.
// Open the Excel file
FileInputStream fis = new FileInputStream(file);
// Access the required test data sheet
HSSFWorkbook wb = new HSSFWorkbook(fis);
HSSFSheet sheet = wb.getSheet("Sheet1");
int TotalCol;
int TotalRow;
// TotalCol = 0;
TotalRow = sheet.getLastRowNum();
TotalCol = sheet.getRow(0).getLastCellNum();
System.out.println("row " + TotalRow + " col " + TotalCol);
int resultcol;
resultcol = 0;
for(int col = 0;col<=TotalCol;col++){
HSSFRow row1 = sheet.getRow(0);
System.out.println("column names " + row1.getCell(col).toString() );
if("result".equalsIgnoreCase(row1.getCell(col).toString().trim()))
{
resultcol = col;
System.out.println("result column number " + resultcol );
}
}
Java lang null pointer exception
in Java/JSP/J2EE
Posted
Have you tried to debug your code?