Only 49 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Any tips on how to generate a huge jTree without getting a StackOverflowError?  RSS feed

 
Max Simpson
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any tips on how to generate a huge jTree without getting a StackOverflowError? The tree shows navigation through a large Web site so the tree is going to be very large. The only thing I can think of it to generate each node's children as that node is clicked on (TreeWillExpandListener) rather than trying to create the entire tree at once. However, if you were to open all of the branches using this method, would you still get a StackOverflowError?
thanks!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like you're creating the tree using a recursive algorithm; you just need to change it to be iterative instead. For example, use something like (in pseudocode)


[ April 19, 2005: Message edited by: Ernest Friedman-Hill ]
 
Steven Bell
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't think you would get a StackOverflowError from creating a large JTree. I would expect an OutOfMemoryError if it was too large. I wonder if you are getting into an infinite loop that is causing the StackOverflowError. You say this show navigation through a web site, is there a link back to a previous page causing a loop?
 
Max Simpson
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Its not an infinite loop, but it is a loop that runs for a long time.. it seems like the VM thinks the loop has been running too long and throws the error.
The problem is that there are multiple ways to get to a single page, so various branches will include that page and any of its children. I have it set up so inside of a branch it will not repeat any pages it already added as nodes in that same branch.
I'm not sure what to try next :-(
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!