I am trying to make an implementation of a Binary Tree for a Words each of a which have a pattern (ex hello - pattern is ABCCD)
I keep getting a null pointer exception on the line it states
while(pos.getPattern() != null || a){
I dont understand why- there are checks in place. Also when I print pos.getPattern() - I get a string not a null value
I could really use some help
public void AddWord(String word) {
TreeNode pos = root;
boolean a = true;
String pat = PatternMaker.MakePattern(word);
while(pos.getPattern() != null || a){
if (pos.getPattern().equals(pat)) {
WordList list = pos.getList();
list.insertWord(word);
pos.setList(list);
a = true;
} else if (pat.compareTo(pos.getPattern()) > 0) {
pos = pos.getRight();
} else {
pos= pos.getLeft();
}
}
if(pos ==null){
pos = new TreeNode(word, pat);
}
}