In my java project, I have a private HashMap field (eggs is an enum, bacon is an object that has an ArrayList field). So it's something like:
class Foo {
private HashMap<Eggs, Bacon> breakfast;
foo() {
this.breakfast = new HashMap<Eggs, Bacon>();}
void setValues(int x) {
ArrayList<Integer> temp;
Bacon b;
for(int i = 0; i < x; i++) {
temp.add(i);}
b = new Bacon(temp);
this.breakfast.put(Eggs.Scrambled, b);}
}
Essentially, even if I make sure to call setValues first in my testClass, a call to breakfast.get() or breakfast.size() will always result in a NullPointerException. In my actual code I have several enum to object mappings in for loops. Using the debugger, I found that the values were set but immediately vanished at the end of each loop. I have no idea why my HashMap field isn't saving the values that get put into it. Even when I changed the field to an ArrayList and set or added values, I'd still get the same nullpointer/outofbounds exception
I can post my actual code if needed but I was wondering if anyone had any insight to this. I'm at my wit's end