Hello,
I'm trying to code a little program which uses Excel as a little DB.
But my code which should read the Excel File got a NullPointerException.
Here's my code: (I've imported everything)
I'm trying to code a little program which uses Excel as a little DB.
But my code which should read the Excel File got a NullPointerException.
Here's my code: (I've imported everything)
Java:
public class DBReader {
List<Mini> miniList = new ArrayList<Mini>();
public List<Mini> readSheet1() throws FileNotFoundException, IOException{
HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream("DB.xls"));
HSSFSheet sheet = wb.createSheet();
for(int i=0;i<=sheet.getLastRowNum();i++) {
System.out.println(i);
String name = "error";
double age = 4;
HSSFRow row = sheet.getRow(i);
if(row.getCell(0).getCellTypeEnum()==CellType.STRING) { //ERROR
name = row.getCell(0).getStringCellValue(); //ERROR if I remove if(row.getCell(0).getCellTypeEnum()==CellType.STRING)
}
if(row.getCell(1).getCellTypeEnum()==CellType.NUMERIC) {
age = row.getCell(1).getNumericCellValue();
}
Mini m = new Mini(name, age);
miniList.add(m);
}
wb.close();
return miniList;
}
}