开发者

Giving error when i adding string to child node

开发者 https://www.devze.com 2023-02-11 14:25 出处:网络
public void createNode(int group){ DefaultMutableTreeNode root = null; DefaultMutableTreeNode child[] = null;
public void createNode(int group){
     DefaultMutableTreeNode root = null;
     DefaultMutableTreeNode child[] = null;
     List<String> list = new ArrayList<String>();

     ExpressionBuilder builder=new ExpressionBuilder();
     list = builder.getExpression(group,0);
     root = new DefaultMutableTreeNode(groupString);    
     defaultTreeModel = new DefaultTreeModel(root);

     for(int i=0; i<list.size();i++){
         child[i] = new DefaultMutableTreeNode(list.get(i));
         defaultTreeModel.insertNodeInto(child[i], root, i);
     }
 }

when i am making child array it is giving me error of null pointer 开发者_开发技巧exception. list is populated correctly.


DefaultMutableTreeNode child[] = null; 

The child array is null.

When you create an array you need to do something like:

DefaultMutableTreeNode child[] = new DefaultMutableTreeNode[???];

So you would need to create the array after you create the List so you know what size to make the array.

0

精彩评论

暂无评论...
验证码 换一张
取 消