Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Exception that I don't quite understand...

807605Jul 12 2007 — edited Jul 12 2007
I am getting these exceptions, which at first I thought I might be doing something wrong, but now I am convinced something screwy is going on. Here are some code snippets:
private ArrayList<Cell> neighbors = new ArrayList<Cell>();
...
Cell n;
while (neighbors.size() != 0) {
  System.out.println("Size = " + neighbors.size());
  n = neighbors.remove(0);
...
}
neighbors is only used in this one method, and I synchronized it to make sure threading was not an issue. The size is always between 0 and 6.

This is the first exception I saw:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
        at java.util.ArrayList.RangeCheck(ArrayList.java:547)
        at java.util.ArrayList.remove(ArrayList.java:387)
        ....
Here is the second one (after I added in the size):
Size = 3
java.lang.IndexOutOfBoundsException: Index: 0, Size: -1940834040
        at java.util.ArrayList.RangeCheck(ArrayList.java:547)
        at java.util.ArrayList.remove(ArrayList.java:387)
        ...
I'm running Java 1.6.0_01 on Fedora 7. Any ideas what could cause this?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 9 2007
Added on Jul 12 2007
6 comments
57 views