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.
精彩评论