Results 1 to 4 of 4
- 10-28-2008, 08:07 PM #1
Creating an array of children while excluding grandchildren.
I am trying to create a new Array to be placed into a combo box but I cannot pull just 1 generation. My tree is set-up like this.
ServerGroup (has children)
+Servers (has children)
+Targets ( doesn't have children)
These are the relevant parts of each class
Java Code://NewDeploymentView.Java Server[] servers = ServerGroup.getChildren(); String[] names = null; for(int i = 0; i < servers.length; i++){ names[i] = servers[i].getName(); System.out.println("Server "+i+" "+names[i]); } c.setItems(names);Java Code://ServerGroup.Java public static Server[] getChildren() { return (Server[]) serverGroupChildren.toArray(new Server[serverGroupChildren.size()]); } public static boolean hasChildren() { return serverGroupChildren.size()>0; }Java Code://Server.Java public boolean hasChildren() { return serverChildren.size()>0; } public Target[] getChildren() { return (Target[]) serverChildren.toArray(new Target[serverChildren.size()]); }I receive this warningJava Code://Target.Java public Server getServerParent(){ return serverParent; } public boolean hasChildren(){ return false; }
I believe what is happening is when I call ServerGroup.getChildren() it digs down and tries to return the great grandchildren(which do not exist) because it doesn't know to stop and just return its own children. I think that serverChildren.size() within Server.Java is where null is but don't know how to work around this or stop it from going this deep. Any help?Java Code:java.lang.NullPointerException at groups.ServerGroup.getChildren(ServerGroup.java:55) at views.NewDeploymentView.createPartControl(NewDeploymentView.java:61)
- 10-28-2008, 09:31 PM #2
"at groups.ServerGroup.getChildren(ServerGroup.java:55 )"
What object is at line 55 in ServerGroup's getChildren method that is null? Then why is it null? Can you test if its null and not call a method/reference a variable if it is null?
What is the value of serverGroupChildren when getChildren is called?
- 10-28-2008, 09:39 PM #3
return serverGroupChildren.size()>0; is line 55. It shouldn't be null because Server objects are the children.
I changed it to return true and now get
line 65 is names[i] = servers[i].getName();Java Code:java.lang.NullPointerException at views.NewDeploymentView.createPartControl(NewDeploymentView.java:65)
- 10-28-2008, 09:40 PM #4
Similar Threads
-
Creating an Array of Objects
By int80 in forum New To JavaReplies: 4Last Post: 08-09-2011, 12:40 PM -
How to load a directory in JTree with Children(On expansion)
By aneesahamedaa in forum AWT / SwingReplies: 0Last Post: 10-13-2008, 01:23 PM -
Need help with creating array of type object
By riz618 in forum New To JavaReplies: 3Last Post: 01-29-2008, 06:14 AM -
Creating Array of LinkedList
By sasikumardr in forum New To JavaReplies: 1Last Post: 12-11-2007, 10:25 AM -
creating array at runtime
By javaplus in forum New To JavaReplies: 4Last Post: 11-08-2007, 10:06 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks