public void display(Date date) {
boolean loop = true;
System.out.println("Events on " + date.toString());
for (int i = 0; i < schedule.length; i++) {
while (loop) {
Date tmp = schedule[i].nextOccurrence();
if (tmp.compareTo(date) == 0) {
System.out.println(schedule[i].nextOccurrence().toString());
}
}
schedule[i].init();
}
}
The above is supposed to print out an occurrence of an event if it falls on the date given to the method. The method nextOccurrence grabs the next occurrence of an event (if its weekly or daily). nextOccurence looks like this for a DailyEvent:
public Date nextOccurrence() {
if (timesCalled == recurrences) {
return null;
}
else {
Calendar cal = Calendar.getInstance();
cal.setTime(startTime);
cal.add(Calendar.DATE, timesCalled);
timesCalled++;
return cal.getTime();
}
}
I call schedule[i].init() to reset the number of times called to 0 (daily events have a limit of number of times they can be called, denoted as an int with the variable recurrences).
Basically, my problem is that I'm getting a NullPointerException for this line:
if (tmp.compareTo(date) == 0) {
I've tried everything and I'm completely lost. Any help would be great!
nextOccurrence()return?