File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

tree.getLastSelectedPathComponent returns null !

 
sherif amer
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am creating a tree and when the below code run it gives null pointer exception as the getLastSelectedPathComponent returns null

logger.debug("tree.getLastSelectedPathComponent() = "+tree.getLastSelectedPathComponent());
String selectedNode=tree.getLastSelectedPathComponent().toString();

any Idea why this happening it was working just yesterday !!!
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if nothing is selected in the tree, the call will return null. If you need further help, post your SSCCE
 
sherif amer
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually i am getting the tree using the below code
tree = ivrTree.getIVRTree(productType); // getIVRTree is the function which construct the tree based on DB selection.
tree.addTreeSelectionListener(this);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

and then i am handling the listener
public void valueChanged(TreeSelectionEvent e) {
logger.debug("inside valueChanged");
String selectedNode=tree.getLastSelectedPathComponent().toString(); //this line always throw the null pointer exception as the tree.getLastSelectedPathComponent() coming with null.
String node=selectedNode.substring(0,selectedNode.indexOf("."));
logger.debug("node = "+node);
logger.debug("controller= "+controller);
controller.setSubMenu(node);
System.out.println(node);
}

Thanks in advance.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll not only get a valueChanged event when something is selected, but also when something is unselected. And when you get this event for the unselection, the tree's selected path is null.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic