• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTree Null Pointer After Refresh  RSS feed

 
Isaac Hewitt
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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)


 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!