• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

tree.getLastSelectedPathComponent returns null !

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !!!
 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic