Vector ArrayIndexOutOfBounds

Posted by Esmond on Stack Overflow See other posts from Stack Overflow or by Esmond
Published on 2010-04-13T14:26:01Z Indexed on 2010/04/13 14:32 UTC
Read the original article Hit count: 306

Filed under:

I'm having an ArrayIndexOutofBounds exception with the following code. The exception is thrown at the line where Node nodeJ = vect.get(j)

but it does not make sense to me since j is definitely smaller than i and Node nodeI = vect.get(i) does not throw any exception.

any help is appreciated.

public static Vector join(Vector vect) throws ItemNotFoundException {

    Vector<Node> remain = vect;
    for (int i = 1; i < vect.size(); i++) {
        Node nodeI = vect.get(i);
        for (int j = 0; j < i; j++) {//traverse the nodes before nodeI
            Node nodeJ = vect.get(j);

            if (nodeI.getChild1().getSeq().equals(nodeJ.getSeq())) {
                nodeI.removeChild(nodeJ);
                nodeI.setChild(nodeJ);
                remain.remove(j);
            }
            if (nodeI.getChild2().getSeq().equals(nodeJ.getSeq())) {
                nodeI.removeChild(nodeJ);
                nodeI.setChild(nodeJ);
                remain.remove(j);
            }
        }
    }
    return remain;
}

© Stack Overflow or respective owner

Related posts about java