index out of bounds

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    index out of bounds

    Code:
     @Override
     public void addElements(Integer i1, Integer i2){
     aL.add(i1, i2);
     }
    }
    Exception in thread "main" java.lang.Index OutOfBoundsExce ption: Index: 1, Size: 0
    at java.util.Array List.rangeCheck ForAdd(ArrayLis t.java:643)
    at java.util.Array List.add(ArrayL ist.java:455)
    at s4409_s4409_pr2 .BagResult.addE lements(BagResu lt.java:23)
    at s4409_s4409_pr2 .QExecUtils.c(Q ExecUtils.java: 53)
    at s4409_s4409_pr2 .S4409_s4409_pr 2.main(S4409_s4 409_pr2.java:38 )
    Java Result: 1
    BUILD SUCCESSFUL (total time: 3 seconds)
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    OK, when you get an exception here's a good tip: READ IT! It's saying that the index is out of bounds. That's a good hint. It says the index is 1 while the size (of the ArrayList) is 0.

    Another good idea is checking the JavaDocs for what you're having problems with. For example, the ArrayList#add(i nt, E) function. That will tell you that an IndexOutOfBound sException is thrown "if the index is out of range (index < 0 || index > size())". Which explains the problem and should help you to solve your situation.

    Comment

    • oll3i
      Contributor
      • Mar 2007
      • 679

      #3
      Thank You Thank You Thank You

      Comment

      Working...