Your question is not very clear.
- What's your code exactly doing? Give more code.
- What's the error you're getting?
You say you get a null-pointer. You cannot get a null pointer as a value returned by contains()
.
However you can get a NullPointerException
if your list has not been initialized. By reading your question now, I'd say that what you show here is correct, but maybe you just didn't instantiate the list.
For this to work (to add a feed URL if it isn't already in the list):
if (!this.rssFeedURLs.contains(rssFeedURL)) {
this.rssFeedURLs.add(rssFeedUrl);
}
then this declaration would do:
private ArrayList<String> rssFeedURLs = new ArrayList<String>();
or initialize your list later on, but before trying to access its methods:
rssFeedUrls = new ArrayList<String>();
Finally... Do you really need a List
? Maybe a Set
would be better if you don't want duplicates. Use a LinkedHashSet
if preserving the ordering matters.