Im working on a school assignment, and im supposed to make a array of hashmap like this:
HashMap<String, Person>[] mood = (HashMap<String, Person>[]) new HashMap<?, ?>[6];
im reading from a file, it goes something like this. the problem is that it gives NullPointerException where i try to put the mood into mood[0]! cant find anything about how the hashmap-array works in my books.. 🙁 would be happy for all help (:
Person p = new Person();
p.name = word[1];
p.age = word[2];
p.mood = word[3];
people.put(p.name, p);
if (p.mood.equals("HAPPY")) {
mood[0].put(p.mood, p); //NullPointerException
}
Basically, you did initialize an array of mood, but it’s initialized with
nulls. So before you can call any method on mood[0] (or at any other indices), you need to put a non-null object inside mood[0].