abstract class Library {
private String day;
public String getDay()
{
return day;
}
public void setDay(String oo){
day = oo;
}
public abstract String setDate();
}
class Books extends Library {
public String setDate() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d-MMM-yyyy");
String dat = this.getDay();
LocalDate localDate = LocalDate.parse(dat, formatter);
LocalDate when = localDate.plusDays(7);
String waitString = when.format(formatter);
return waitString;
}
}
class Main {
public static void main(String[] args) {
for (int i=0; i<10; i++){
System.out.println(rent[i].getDay() + rent[i].setDate());
}
}
Java gives me an Exception in thread "main" java.lang.NullPointerException from String dat = this.getDay();
, but when I change it to like String dat = 23-Mar-2019
it works fine. It seems like java is not responding to "this.getDay()" from the extended class, but I do not know how to fix this.