I have a problem with reading xls files into Java usin jxl library.
Could you tell me what is wrong my code? I attached below. Something is wrong wif fillData method. The console returns:
Exception in thread "Thread-1" java.lang.NullPointerException
at StudentLogin.fillData(StudentLogin.java:104)
at StudentLogin.<init>(StudentLogin.java:70)
at Login$PBar.run(Login.java:103)
at java.base/java.lang.Thread.run(Unknown Source)
Thank you in advance for your help.
public void fillData(File file) {
Workbook workbook = null;
try {
workbook = Workbook.getWorkbook(file);
}
catch (Exception e) {
}
Sheet sheet = workbook.getSheet(0);
headers.clear();
for (int i = 0; i < sheet.getColumns(); i++) {
Cell cell = sheet.getCell(i, 0);
headers.add(cell.getContents());
}
data.clear();
for (int j = 1; j < sheet.getRows(); j++) {
Vector<String> d = new Vector<String>();
for (int i = 0; i < sheet.getColumns(); i++) {
Cell cell = sheet.getCell(i, j);
d.add(cell.getContents());
}
d.add("\n");
data.add(d);
}
}