As you remove each child the number of children in the branch group is
reduced. If you want to remove the child nodes do this:
for( int i = (bg.numChildren() - 1); i >= 0; i-- ) {
bg.removeChild( i );
}
This removes the child nodes from the back of the list rather than the front
as you were doing.
Hope this helps,
Chris
-----Original Message-----
From: Liming CHEN [mailto:[EMAIL PROTECTED]]
Sent: 31 January 2001 13:15
To: [EMAIL PROTECTED]
Subject: [JAVA3D] problem with removeChild()
Hi,
I add seven children (Behaviour) to a BranchGroup. Then I try to remove all
these
children by the following codes
int childNum = bg.numChildren();
for( int j =0; j<childNum; j++) {
System.out.println(" test child number" + childNum + " " + j );
bg.removeChild(j);
}
However, there is a error message as follows:
test child number7 0
test child number7 1
test child number7 2
test child number7 3
test child number7 4
Exception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException: 4 >= 3
at java.util.Vector.elementAt(Vector.java:417)
at javax.media.j3d.GroupRetained.doRemoveChild(GroupRetained.java:312)
at javax.media.j3d.GroupRetained.removeChild(GroupRetained.java:303)
at javax.media.j3d.Group.removeChild(Group.java:201)
at HumanBehavior.setBehaviour(HumanBehavior.java:176)
at VirtualAgent.actionPerformed(VirtualAgent.java:301)
at java.awt.MenuItem.processActionEvent(MenuItem.java:531)
at java.awt.MenuItem.processEvent(MenuItem.java:495)
the message show the index is invalid. However I think 4 is less than the
numChildren (that is 7). It should be okay. I can not figure out the reason.
Is it a bug or I make a mistake somewhere?
thanks
liming
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".