My program crashes due to a null pointer exception.
Snip of Stack Trace:
java.lang.NullPointerException
at com.my.GRTRecTimeSortComparator.compare(SourceFile:15)
That’s well and good. But my problem is that line 15 is the class declaration:
15 public class GRTRecTimeSortComparator implements Comparator<GRTRecord> {
16 @Override
17 public int compare(GRTRecord rec1, GRTRecord rec2) {
18
19 int returnVal=rec1.getRecordCalendar().compareTo(rec2.getRecordCalendar());
20 return returnVal;
21 }
22}
It’s calling out the Compare function, but I don’t see an issue with that either. Every record has a Unique Calendar assigned to it as well.
Any ideas? What have I done wrong here?
Edit: in response to queries:
No, there is nothing strange about the class itself, other than the fact I wrote it.
I AM using Proguard. Maybe the Obfuscation is replacing things incorrectly?
I’m writing up tests for the records right now. They SHOULDN’T be null, nor should the Calendars; I use them immediately before, and get good results.
Maybe I’m just passing the ArrayList incorrectly.
EDIT 2:
Logging lines inserted into the class never get run.
No matter what I add or do to the class, the null pointer always resolves to the class declaration line.
Removed Proguard Obfuscation, and still no dice.
I’m REALLY frustrated.
Edit 3:
For Future Users:
Proguard ruins your stack trace. That was the cause of the Above. Remove proguard if you run into issues.
The CAUSE was actually a corrupted record in the dataset.
I strongly suspect that the debug information is just out of sync. Put logging into your
comparemethod. I would log (in order):rec1rec2rec1.getRecordCalendar()rec2.getRecordCalendar()If this isn’t the problem, is there anything “odd” about the class in any other way? For example: