“ AWT-EventQueue-0” java.lang.StackOverflowError-尝试创建JTree文件夹结构时

时间:2018-08-22 06:33:42

标签: java swing stack-overflow jtree defaultmutabletreenode

我正在尝试从输出构建JTree文件夹结构。这是方法。

  • 我叫系统
  • 获取文件夹列表
  • 循环浏览文件夹列表并创建一个列表
  • 从列表中创建文件夹结构

当文件夹数较少时,此方法工作正常,但当文件夹数较多时,则抛出堆栈溢出错误。

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
          }
        }
      }

0 个答案:

没有答案