We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Adding a list to the end of a list
Page Index Toggle Pages: 1
Adding a list to the end of a list (Read 649 times)
Adding a list to the end of a list
Jan 17th, 2010, 10:43am
 
Hi,

I'm trying to use the Twitter API to build up a list of tweets to use later in the program. Using the Twitter4J library, I've gotten this far:

Code:
try {
tempTweets = twitter.getPublicTimeline(); //returns 20 most recent public tweets
for( int i=0; i<tempTweets.size(); i++ ) {
Status status = (Status)tempTweets.get(i);

tweets.add(0,"hello");
println(status.getUser().getName() + ":" + status.getText());
}
}
catch( TwitterException e) {
println(e.getStatusCode());
}


This successfully performs call after call, printing the tweets. Since only 20 tweets can be called at once, I need to run the code I have a few times, each time adding the resulting list to the end of a 'master' list, which will, after the specified number of runs (let's say 5), contain 100 tweets. Everything I've tried using the add and addAll functions has resulted in a NullPointerException, however, so I'm hoping someone can point me in the right direction. I have a second list defined, called 'tweets', and I need to add 'tempTweets' to the end of it each time this code runs.

Any help would be greatly appreciated - thank you in advance!
Re: Adding a list to the end of a list
Reply #1 - Jan 17th, 2010, 10:59am
 
sounds like you haven't initialised your tweets ArrayList.

add Arraylist tweets = new ArrayList(); to the top of your code, before setup().

you also appear to have created 5 copies of this question. please delete the others.
Re: Adding a list to the end of a list
Reply #2 - Jan 17th, 2010, 11:17am
 
koogy wrote on Jan 17th, 2010, 10:59am:
sounds like you haven't initialised your tweets ArrayList.

add Arraylist tweets = new ArrayList(); to the top of your code, before setup().

you also appear to have created 5 copies of this question. please delete the others.


That was it! I had set it up as a List. Thank you very much. I should be able to cycle through items in this ArrayList now using a simple loop, right

Also - didn't notice I'd created 5, it kept giving me an error when I clicked 'Post' - I guess it was going through anyways. Deleted, sorry about that.
Page Index Toggle Pages: 1