java.lang.StackOverflowError
Hi,
I'm trying to create a Binary search tree, for a dictionary which comes from an external file, that the user defines.
It works fine with a small dictionary file, but once the file has more then 4200 items or so, it causes an error, and gives me the message:
Exception in thread "main" java.lang.StackOverflowError
at java.lang.String.compareTo(Unknown Source)
It is coming from this portion of the code:
protected TreeNode insertItem(TreeNode tNode, KeyedItem newItem){
TreeNode newSubtree;
//position of insertion found
//insert after leaf
//create a new node
if(tNode ==null){
tNode =new TreeNode(newItem, null,null);
return tNode;
}//end if
KeyedItem nodeItem = (KeyedItem)tNode.getItem();
//search the left subtree
if (newItem.getKey().compareTo(nodeItem.getKey()) < 0){
newSubtree = insertItem(tNode.getLeft(), newItem);
tNode.setLeft(newSubtree);
return tNode;
}
//search the right subtree
else{
newSubtree = insertItem(tNode.getRight(), newItem);
tNode.setRight(newSubtree);
return tNode;
}//end if
}//end insertItem
and particularly with these lines:
[
if (newItem.getKey().compareTo(nodeItem.getKey()) < 0){
+
newSubtree = insertItem(tNode.getRight(), newItem);
does anybody know how to fix this problem please let me know?

