hi, thanks for the suggestion..i got it right now On Apr 6, 5:17 pm, Bob Kerns <[email protected]> wrote: > ArrayList would be a better choice; Vector has extraneous method > synchronization. > > But either one suffers from the problem that you'll need to store > Integer objects rather than int values, which will cause GC. That > should not be a problem here, I just point it out as a difference from > using an int[] array. You can create your own class that acts like > ArrayList<int>, were that a legal construct -- it's not difficult. > Whenever you grow the array, at least double it in size, or you'll end > up paying an exponential cost in copying the data. > > But again, that's not a problem you need to worry about here. Just use > ArrayList<Integer>. Using it's add(Integer) method, you won't even > need to maintain your 'i' variable. > > On Apr 6, 9:29 am, Michael Rueger <[email protected]> wrote: > > > On 4/6/2010 6:17 PM,raqzwrote: > > > > I am trying to record the position into the array a[]. And everytime > > > somebody clicks some row in the list, the i value needs to be > > > incremented. Anything wrong with that? Please suggest some other > > > alternative if you have anything in mind. > > > You need a growing data structure like Vector for this and then append > > the values. > > > Vector positions = new Vector(); > > positions.add(position); > > > The above code isn't complete, left as an exercise to the reader ;-) > > > You defined a zero size array and trying to access it will crash. > > > Michael > > > > On Apr 6, 12:09 pm, Michael Rueger<[email protected]> wrote: > > >> On 4/6/2010 6:03 PM,raqzwrote: > > > >>> Hi, I am trying to record the selection made by the user in the array. > > >>> But when I run the app, it crashes the moment I click something. > > >>> Please let me know what could be done for this. > > > >>> public class ListViewExample extends ListActivity > > >>> { > > >>> public int a[]; > > >>> public int i=0; > > > >> ... > > > >>> a[i++]=position; > > > >> That's probably the culprit. > > >> What are you trying to do here? > > > >> Michael
-- 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 To unsubscribe, reply using "remove me" as the subject.

