i think i never saw so many similiar responses to the same question.. lol
that was original.. keep up the good work guys : ))

-----Original Message-----
From: Discussion list for Java 3D API
[mailto:[EMAIL PROTECTED]]On Behalf Of J. Lee Dixon
Sent: Wednesday, January 31, 2001 8:44 AM
To: [EMAIL PROTECTED]
Subject: Re: [JAVA3D] problem with removeChild()


When you remove a child, they all shift down by one.

Try this:
for( j=0; j<childNum; j++)
{
  bg.removeChild(0);
}

An even better way:

while( bg.numChildren() > 0 )
{
  bg.removeChild(0);
}

-Lee

J. Lee Dixon
SAIC - Celebration, FL
407-566-1438
[EMAIL PROTECTED]    AOL: LeeOrlando

> -----Original Message-----
> From: Liming CHEN [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 31, 2001 8:15 AM
> 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".

===========================================================================
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".

Reply via email to