wood burning stoves
The moose likes Beginning Java and the fly likes OutOfBoundsException Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "OutOfBoundsException Error" Watch "OutOfBoundsException Error" New topic

OutOfBoundsException Error

Karen Baog
Ranch Hand

Joined: Mar 02, 2005
Posts: 120
My test server program receives packets from the Client.
Im my server program the data received is assigned to:

When my client is set to continually send a message, eventually (only after a few seconds) the server throws an ArrayIndexOutOfBoundsException Error.

I assume the data[] doesn't get cleared and is filled very quickly.
I would have thought that, because the data array is declared and initialized inside the for loop, the garbage collector would take care of it.

[ July 13, 2005: Message edited by: Karen Baog ]

amerzil co-ed student<br />"Praise be the Code"
Karen Baog
Ranch Hand

Joined: Mar 02, 2005
Posts: 120
I think I need to expand on this a bit more.

Hre is an expanded code. I'll use values instead of variable names, where possible for clarity. I have opted not to show the exception clauses as it will only clog up the code.

Pleeeease, help!
[ July 13, 2005: Message edited by: Karen Baog ]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Can you please post the exact error message? It will include the line of code that is throwing the exception. This will greatly help us be able to determine what the problem might be.


Java API Documentation
The Java Tutorial
Karen Baog
Ranch Hand

Joined: Mar 02, 2005
Posts: 120
Digging deeper into this, I see that the StringBuffer gets filled up.
But I can't find any method of clearing it.
The .delete(int, int) don't work.

Any suggestions?
Karen Baog
Ranch Hand

Joined: Mar 02, 2005
Posts: 120
I've tried several methods to try to clear up the StringBuffer as suggested here, but still can't get it to work. The StringBuffer just keeps growing.


I do hope that someone here would look a this.
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059

I think you're correct.
Is newMsg.length() greater than data.length ??
In other words, can you always assign newMsg.charAt(i) to data[i] ?

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
I agree. Here's the link: http://aspose.com/file-tools
subject: OutOfBoundsException Error
It's not a secret anymore!