Hey!
I need to add a child node (its name is stored in Object child1) to the specific parent node (Object hierarchy). To do that, I try to find the parent node and then add the child node to it. However, e.printStackTrace() provides the error message (see below). What am I doing wrong? Thanks!
private processHierarchyChild(Object hierarchy, Object child1) {
MutableTreeNode childNode = new DefaultMutableTreeNode(child1.toString());
try {
TreePath path = tree1.getNextMatch(hierarchy.toString(), 0, Position.Bias.Forward);
System.out.println(path);
if (path == null) {
} else {
MutableTreeNode parentNode = (DefaultMutableTreeNode)(MutableTreeNode) path.getLastPathComponent();
treeModel.insertNodeInto(childNode, parentNode, parentNode.getChildCount());
} } catch (Exception e) {
e.printStackTrace();
}
}
java.lang.NullPointerException
at SystClasses.TreeEditTest.processHierarchyChild(TreeEditTest.java:326)
at SystClasses.TreeEditTest.processHierarchy(TreeEditTest.java:304)
at SystClasses.TreeEditTest.<init>(TreeEditTest.java:78)
at SystClasses.Form.createDocumentsLeftPanel(Form.java:252)
at SystClasses.Form.createBase(Form.java:162)
at SystClasses.Form.access$000(Form.java:44)
at SystClasses.Form$2.actionPerformed(Form.java:143)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6267)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6032)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2478)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)