I am using Twitter4j to fetch the followers of a given user. At some point I always hit the rate limit. I am happy for the program to sleep for 15 minutes to over come this. However when it wakes, I get an error.
See the following code:
protected IDs fetchAndStoreFollowers(TwitterUser user) {
Twitter twitter = this.getTwitterApi();
long cursor = -1;
IDs ids = null;
do {
try {
ids = twitter.getFollowersIDs(user.getId(), cursor);
System.out.println("Got a followers batch");
cursor = ids.getNextCursor();
this.storeFollowers(user, ids);
System.out.println("Saved!");
} catch (TwitterException e) {
System.out.println("Oh no! Rate limit exceeded... going to sleep.");
handleTwitterException(e);
System.out.println("Waking up!");
}
} while (ids.hasNext());
return ids;
}
After waking up from the sleep the program throws a NullPointerException
on this line:
} while (ids.hasNext());
Can anybody spot why?