• 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

JTree Null Pointer After Refresh

 
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I recently added TreeWillExpandListener to my JTree, to be sued to prevent the expansion of a certain directory within the JTree. This part of the code work alright, but when something is deleted in the JTree, the code throws the following maojor exception:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at film_titles.poster_manager.DocumentTree.treeWillExpand(Unknown Source)
at javax.swing.JTree.fireTreeWillExpand(JTree.java:2723)
at javax.swing.JTree.setExpandedState(JTree.java:3421)
at de.schlichtherle.io.swing.JFileTree.setExpandedDescendants(JFileTree.java:394)
at de.schlichtherle.io.swing.JFileTree.refresh(JFileTree.java:381)
at de.schlichtherle.io.swing.JFileTree.refresh(JFileTree.java:337)
at film_titles.poster_manager.DocumentTree$3.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
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)

When I remove the code with the method below, the exception no longer appears. When I try to test for a null value on the second line of the method, the exception still appears.
if(DocumentTree.this.getLastSelectedPathComponent().toString() == null)


 
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
So DocumentTree.this.getLastSelectedPathComponent() returns null.
 
Isaac Hewitt
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This works.
As usual, the folks at the Ranch are very helpful, and so I thank you, (also for not giving me the exact solution). Many thanks to you for your prodding, Rob Prime.
 
Rob Spoor
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're welcome.
 
Curse your sudden but inevitable betrayal! And this tiny ad too!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic