Здравствуйте, работа с excel, задача такова: нужно найти тех, у кого стаж больше n. программа готова, по сути все должно работать но ругается на 2 строки
Main.java:
public class Main {
HSSFWorkbook workbook = null;
List<Employee> list = new ArrayList<>();
public static void main(String[] args) {
Main m = new Main();
m.getData();
m.showWithSeniorityNotLessThan(3);
}
// получаем дату, записываем ее в list в виде класса Employee
public void getData(){
try {
workbook = new HSSFWorkbook(new FileInputStream("E:\\Book.xls"));
} catch (IOException e) {
e.printStackTrace();
}
Sheet sheet = workbook.getSheetAt(0);
int limit = sheet.getLastRowNum();
for (int i = 1; i <= limit; i++) {
Row row = sheet.getRow(i);
String name = row.getCell(0).getStringCellValue();
int seniority = (int) row.getCell(1).getNumericCellValue();
int salary = (int) row.getCell(2).getNumericCellValue();
String appointment = row.getCell(3).getStringCellValue();
list.add(new Employee(name, seniority, salary, appointment));
}
}
// пробегаем по списку, выводим если подходит
public void showWithSeniorityNotLessThan(int limit){
for (Employee e : list){
if (e.getSeniority() >= limit) System.out.println(e);
}
}
}
Employee.java
class Employee {
private String name;
private int seniority;
private int salary;
private String appointment;
public Employee(String name, int seniority, int salary, String appointment) {
this.name = name;
this.seniority = seniority;
this.salary = salary;
this.appointment = appointment;
}
@Override
public String toString() {
return name + " | " +
seniority + " | "
+ salary + " | "
+ appointment;
}
public int getSeniority() {
return seniority;
}
}
ошибка:
Exception in thread "main" java.lang.NullPointerException
at Main.getData(Main.java:38)
at Main.main(Main.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Process finished with exit code 1