T
Tk
I have code :
public class ReadXL {
/** Location where the Excel has to be read from. Note the forward Slash
*/
//C:\Documents and Settings\tkulej\Pulpit\java excel\jw-0322-poi
public static void main(String argv[]){
String fileToBeRead="C:/cos.xls";
try{
System.out.print("start"+"\n");
HSSFWorkbook workbook = new HSSFWorkbook(new
FileInputStream(fileToBeRead));
HSSFSheet sheet = workbook.getSheetAt(0);
HSSFRow row = sheet.getRow(0);
HSSFCell cell = row.getCell((short)3);
if( cell == null)
{
System.out.print("empty");
} else {
System.out.print("something is
there");
}
}catch(Exception c) {
System.out.println("!! Bang !! xlRead() : " + c );
}
}
}
This code is not good because I have exception : !! Bang !! xlRead() :
java.lang.NullPointerException
I must read a cell but if this cell is empty this exeception happen, how to
fix this application ?
public class ReadXL {
/** Location where the Excel has to be read from. Note the forward Slash
*/
//C:\Documents and Settings\tkulej\Pulpit\java excel\jw-0322-poi
public static void main(String argv[]){
String fileToBeRead="C:/cos.xls";
try{
System.out.print("start"+"\n");
HSSFWorkbook workbook = new HSSFWorkbook(new
FileInputStream(fileToBeRead));
HSSFSheet sheet = workbook.getSheetAt(0);
HSSFRow row = sheet.getRow(0);
HSSFCell cell = row.getCell((short)3);
if( cell == null)
{
System.out.print("empty");
} else {
System.out.print("something is
there");
}
}catch(Exception c) {
System.out.println("!! Bang !! xlRead() : " + c );
}
}
}
This code is not good because I have exception : !! Bang !! xlRead() :
java.lang.NullPointerException
I must read a cell but if this cell is empty this exeception happen, how to
fix this application ?