The ArrayList.ensureCapacity(int min) does not change the size. So even
the minimum capacity of this array increase, this size of this array still
keeps same. if the size happens to be less than the minicapacity (in your
case), the error will occurs. If you check the size value, I bet it will
less than index+1 in your case.

Jack

-----Original Message-----
From: Rajat Pandit [mailto:[EMAIL PROTECTED]
Sent: Tuesday, November 04, 2003 8:45 PM
To: Struts Users Mailing List; [EMAIL PROTECTED]
Subject: ArrayList problem


hello,
i am stuck in a simple piece of code, for which i have spent the last
2hrs and i seriously dont know what is wrong with this.
this is the setter method for an indexed property that i am using. sinci
i dont know how the size required i am checking if the index is >= the
size and in that case i am increasing the size() by idx + 1.

     public void setName(int idx, String value) {
         System.err.println("----------------");
         System.err.println("In the setName method");
         System.err.println("Idx: " + idx + ", Value: " + value);
         System.err.println("----------------");
         if (idx >= name.size()) {
             this.name.ensureCapacity((idx + 1));
         }

         this.name.add(idx,value);

     }



in a seperate problem, only idx (in the right order 0,1,2,3,4) works fine.

this particular method works fine for idx = 2 and anything bigger than
that gives errror.

aused by: java.lang.IndexOutOfBoundsException: Index: 2, Size: 1
        at java.util.ArrayList.add(ArrayList.java:367)
        at
com.hedging.admin.productmanagement.StateForm.setStartValue(StateForm.java:9
1)
        ... 43 more
i would be reaslly thankful in someone could suggest me something.


--


Rajat Pandit | [EMAIL PROTECTED]
+91 612 3117606
[ Developer and Part Time Human Being]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to