On Jun 24, 2:18 pm, tstanly <[email protected]> wrote:
> hi all,
>
> it's so strange!!
>
> i have a list decleared:
> public static List<String> list1=new ArrayList<String>();
> and use
>
> list1.add(str);
> it is ok!
>
> but use
> list1.add(index,str);
> program will be error

You probably tried to write at an index which doesn't exist's yet.

This could happen, when index is out of bound. For example if index
starts with 1.

public static List<String> list1=new ArrayList<String>();

int index = 1;
list1.add(index, str); // -> Trying to add before the object on
position 1. But as you don't have added any strings before it, there
is no object at position 1 (remember: It's a zero based index, this
means first object has the index 0, second object has the index 1
etc).

public static List<String> list1=new ArrayList<String>();

int index = 0;
list1.add(index, str); // should work



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to