NullPointerException when trying to add an object to a PriorityQueue

addition, java, nullpointerexception, priority-queue

Solution

You haven't initialized the queue.

nodes = new SomePriorityQueue();

Problem

i keep getting a null pointer exception when trying to add an object to a priority queue i initialize the queue: ``` private PriorityQueue<NodeObject> nodes; ``` and here i try to add to it: ``` NodeObject childNode = new NodeObject(child, 1); nodes.add(childNode); ``` why doesn't this work? i know my NodeObject is not null because i create it right before i add it.

Original source