troubleshooting Question

Array Index Out of Bounds Exception

Avatar of leprechain
leprechain asked on
JavaJava EE
47 Comments1 Solution770 ViewsLast Modified:
Hi, I am getting an exception of "java.lang.ArrayIndexOutOfBoundsException: 2 >= 2" in my java servlet.
my exception seems to occur at line "        if (((InteractiveItemWrapper)itemVector.elementAt(i)).modelContentKey == ((ModelContentWrapper)contentVector.elementAt(j)).modelContentKey) {".

here is my code which I am looping through

    for (int i = 0; i < itemVector.size(); i++) {
      System.out.println("In i at position = " + i);

      for (int j = 0; j < contentVector.size(); j++) {
        System.out.println("In j at position = " + j);      
        if (((InteractiveItemWrapper)itemVector.elementAt(i)).modelContentKey == ((ModelContentWrapper)contentVector.elementAt(j)).modelContentKey) {
          System.out.println("In 1");
          if ((((InteractiveItemWrapper)itemVector.elementAt(i)).status).equals(InteractiveItem.INTERACTIVEITEM_STATUS_ACTIVE)) {
            System.out.println("In 2");
            if (itemRemovedVector.size() > 0) {
              System.out.println("In 3");                  
              System.out.println("In 4");                  

Note: itemvector size is 3 and contentVector size is 6.

Can anyone see where my problem lies and if so then how to correct it?

Join our community to see this answer!
Unlock 1 Answer and 47 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 47 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros