“AWT-EventQueue-0” java.lang.StackOverflowError - While trying to create JTree folder structure

“AWT-EventQueue-0” java.lang.StackOverflowError - While trying to create JTree folder structure



I'm trying to build a JTree folder structure from a output. Here is the approach.


JTree



This is working fine when the number of folders are less however when the number of folders are more it is throwing a stack overflow error.


private static DefaultMutableTreeNode builtTreeNode(String comptype) {
try
List<Node> nodeList = new ArrayList<>();
//Defin the configuration context
APIObject fol = //Call the other system to get folders;
DefaultMutableTreeNode dmtNode = null;
System.out.println(" Folder Size " +fol.length);
for (int i = 0; i < fol.length; i++)
if(getParentFolder().getName() == null && !getParentFolder().getIsActive())
dmtNode = new DefaultMutableTreeNode(df.getName().toString());
nodeList.add(new Node(df.getName().toString()));// Set the ROOT folder in nodelist

if(getParentFolder().getName() != null )
//nodeList.add(new Node("Child", "Parent"));
//add remaining folders to nodelist
nodeList.add(new Node(df.getName(), df.getParentFolder().getName()));


findChild(dmtNode, nodeList); //
return dmtNode;

private static void findChild(DefaultMutableTreeNode parent, List<Node> list)
for (int i = 0; i < list.size(); i++)
if (list.get(i).parent != null && list.get(i).parent.equals(parent.toString()))
DefaultMutableTreeNode child = new DefaultMutableTreeNode();
child = new DefaultMutableTreeNode(list.get(i).label);
parent.add(child); // Getting exception from this line of code
findChild(child, list); // child of child







less compared to what? where is the error thrown? what is the complete stacktrace?
– Stultuske
Aug 22 at 6:36





It's probably best not to try and create the entire tree at once. Even before a stack overflow, it will contain far more files that the user could ever trawl through. Instead look to create it lazily, as done in the File Browser GUI. That code will fill only the top level directories, waiting for user selection of a directory before populating the files within it. General tip: For better help sooner, post a Minimal, Complete, and Verifiable example or Short, Self Contained, Correct Example.
– Andrew Thompson
Aug 22 at 6:48





@Stultuske its thrown in from these lines - parent.add(child); // Getting exception from this line of code findChild(child, list); // child of child Below is the error - Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError at javax.swing.tree.DefaultMutableTreeNode.isNodeAncestor(Unknown Source) at javax.swing.tree.DefaultMutableTreeNode.insert(Unknown Source) at javax.swing.tree.DefaultMutableTreeNode.add(Unknown Source) at com.exacttarget.login.Login.findChild(Login.java:634)
– Sanjay
Aug 22 at 15:51










By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ

How do I collapse sections of code in Visual Studio Code for Windows?