0

I'm trying to move around nodes and append them either a 0 or a 1 depending on their position, as I'm doing a Huffman compression test.

However, when trying to use the method isLeaf() which is from javax.swing.tree.

Here's the segment of the code that's giving me issues.

private static void createTestMap(
final Node node,
final String string,
final Map<Character, String> map)
{
    if(!node.isLeaf())
    {
       createTestMap(nodo.leftChild, string + "0", map);
       createTestMap(nodo.rightChild, string + '1', map);
    }
    else
    {
        map.put(node.test, string);
    }
}

With the node code on a different class. On this one it's giving me an error:

cannot find symbol - method isLeaf() 

I'm extremely new to Java and coding in general so I'm not quite sure what's missing, as I've seen this method being used in several programs related to Huffman compression through nodes.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Eleber
  • 9
  • Possible duplicate of [What does a "Cannot find symbol" compilation error mean?](https://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-compilation-error-mean) – slim Dec 11 '17 at 17:07

2 Answers2

1

The isLeaf() method is defined for a sub-class of TreeNode, specifically DefaultMutableTreeNode.

I've seen this method being used in several programs

Always consult the Java Docs to understand random snippets of code from the internet.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
1

The only two Node classes in the JDK are javax.xml.soap.Node and org.w3c.dom.Node.

You should be using javax.swing.tree.TreeNode or indeed javax.swing.tree.DefaultMutableTreeNode.

user207421
  • 305,947
  • 44
  • 307
  • 483