java.lang.NullPointerException in SourceListTreeUI after adding an item

9 views
Skip to first unread message

MacWidgetsUser

unread,
Aug 8, 2010, 12:13:11 PM8/8/10
to Mac Widgets for Java
I get a NullPointerException after trying to add a SourceListItem

public void treeNodesInserted(TreeModelEvent e) {
TreePath path = e.getTreePath();

Object root = tree.getModel().getRoot();
TreePath pathToRoot = new TreePath(root);
if (path != null && path.getParentPath() != null
&&
path.getParentPath().getLastPathComponent().equals(root)
&& !tree.isExpanded(pathToRoot)) {
TreeUtils.expandPathOnEdt(tree, new
TreePath(root));
}


}

The Exception is thrown when tree.getModel().getRoot(); is called. The
tree seems to be null.

if(tree != null) {
Object root = tree.getModel().getRoot();
TreePath pathToRoot = new TreePath(root);
...
}

Fixes the issue.

I call the addItem after the whole ui is created.

Ken Orr

unread,
Aug 8, 2010, 6:42:29 PM8/8/10
to Mac Widgets for Java
Hi Simon,

Make sure you're adding your items on the Event Dispatch Thread.

-Ken

On Aug 8, 9:13 am, MacWidgetsUser <simon.buett...@googlemail.com>
wrote:

MacWidgetsUser

unread,
Aug 9, 2010, 4:10:35 AM8/9/10
to Mac Widgets for Java
Hi Ken,
thats exactly what i am doing. SwingUtilities.isEventDispatchThread()
is true
Reply all
Reply to author
Forward
0 new messages