My node is having list of nodes(as children).
ref.get(L.get(t)).children.add(N);
L.get(t)
is giving my parent node. ref.get(L.get(t))
is another node which I want to work with.
I wanted to add my new node N
to children of ref.get(L.get(t))
. While debugging I can see a node in ref.get(L.get(t))
but throwing NullPointerException
.
public void CreateNode(Node m,ArrayList<Node> S,HashMap<Node,Node> ref,ArrayList<String> L) {
Node N = new Node(m.val,m.data);
ref.put(m,N);
if(S.isEmpty()) {
S.add(N);
} else {
Node c =ref.get(L.get(t)); //Showing C as null
ref.get(L.get(t)).children.add(N); //unable to access node in ref.get(L.get(t))
System.out.println(ref.get(L.get(t)).val);
S.add(N);
t++;
}
}