Universal Robots+

Unusual NullPointerException

The URCap I’m writing contains a JTree object as part of its UI, as seen below.

Screenshot%20from%202019-01-10%2010-07-57

I can alter the structure of the tree just fine, and I have gotten to be bug free. However once a node has been removed from the tree, tapping any of the blank space below the list of nodes gives this big NullPointerException window, not like the usual window which would tell me where in my java code the error was thrown.

The unusual thing about this error is that it only occurs when testing the cap on a real robot, in the simulator this error doesn’t occur. I’ve tested it on a real robot software 3.7 and 3.8, and the error is thrown on both. Likewise I’ve tested it on simulator software 3.7 and 3.8, and the error isn’t thrown on either. I couldn’t test the cap on earlier versions of software as it was built on sdk 1.4.

I’ve tried wrapping the body of the TreeSelectionListener in a try{}/catch(NullPointerExcetion){} but that hasn’t helped.

How do you remove a node (Code wise)? It could be that you don’t do enough checks before removing it, causing the remove method to remove non existing node or something like that.

The code I used to remove a node is

TreePath selectedPath = view.waypointTree.getSelectionPath();
view.treeModel.removeNodeFromParent((DefaultMutableTreeNode)selectedPath.getLastPathComponent());

This is the same code as used in the TreeDemo example from oracle:
https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/uiswing/examples/components/DynamicTreeDemoProject/src/components/DynamicTree.java

I tried to identified the exception and came across this post. Hope it will help!
Link