0

I have a class called people that has its own name, id etc... I have a full list of people in an array list public ArrayList<people> pList; When I click on some names I want to add the people in pList to public ArrayList<people> followList; Doing followList.add(pList.get(position)) doesn't work. What is the proper way to do this.

Also, on another click I would like to remove the particular object from the followList so I tried doing followList.remove(pList.get(position)) but obviously it doesn't work as well.

Im basically trying to have a list of people from the original list.

3
  • it sais im getting a null pointer exception Commented Aug 26, 2011 at 20:38
  • Have you initialized followList with something like new ArrayList<people>()? Commented Aug 26, 2011 at 20:42
  • good catch, make an answer and i will check it. Thanks Commented Aug 26, 2011 at 21:03

2 Answers 2

1

The followList seems to be not initialized. You should call initialize it with new ArrayList<people>() before adding to or removing from it.

Sign up to request clarification or add additional context in comments.

Comments

0

Are you sure that you have instantiated the ArrayList followList, and that there is in fact a element at pList[position]?

1 Comment

If there was no element at the specified position then IndexOutOfBoundsException would be thrown.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.