JAVA Getting a nullpointer exception in an "if" statement?
<pre><code>public void display(Date date) {
        boolean loop = true;
    System.out.println("Events on " + date.toString());
    for (int i = 0; i &lt; 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();
    }
}
</code></pre>

<p>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:</p>

<pre><code>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();
        }
    }
</code></pre>

<p>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).</p>

<p>Basically, my problem is that I'm getting a NullPointerException for this line:</p>

<pre><code>if (tmp.compareTo(date) == 0) {
</code></pre>

<p>I've tried everything and I'm completely lost.
Any help would be great!</p>
