Why can't I push onto stack? Java 6 generics -
i have no idea why i'm unable simple push generic type of object onto stack. i've decided need figuring out. have:
private void preordertrav(bstnode<k> node) { if(node != null){ mystack.push(node); //null pointer exception while(!mystack.isempty()){ mystack.pop(); node = node.getleft(); mystack.push(node.getright()); mystack.push(node.getleft()); } } }
this being called constructor:
public bstsortedlistiterator(bstnode<k> root) { preordertrav(root); }
anyone have ideas? error, way:
exception in thread "main" java.lang.nullpointerexception @ bstsortedlistiterator.preordertrav(bstsortedlistiterator.java:33) @ bstsortedlistiterator.preordertrav(bstsortedlistiterator.java:31) @ bstsortedlistiterator.<init>(bstsortedlistiterator.java:43) @ bstsortedlist.iterator(bstsortedlist.java:130) @ webdictionary.main(webdictionary.java:135)
if sure getting nullpointerexception
mystack.push(node);
and have mentioned there check
if(node != null)
only thing can null mystack. or else incomplete information.
exception in thread "main" java.lang.nullpointerexception @ bstsortedlistiterator.preordertrav(bstsortedlistiterator.java:33)
is mystack.push(node);
line number 33 in bstsortedlistiterator.java