我正在创建一个应用程序来返回特定位置的所有特定用户。我使用getFollowersList来获取一些名人的追随者(例如美国),然后使用user.getStatus()。getPlace()。getCountry()获取该追随者的位置。但它似乎没有用。有什么建议为什么会发生这种情况?每次返回null。 这是代码:
BufferedWriter red = null;
try {
red = new BufferedWriter (new FileWriter ("newcode.txt"));
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ArrayList<User> followers = new ArrayList<User>();
PagableResponseList<User> usersResponse = null;
long cursor = -1;
do {
try {
if (0 < args.length) {
usersResponse = twitter.getFollowersList(args[0], cursor, 150);
System.out.println("size() of first iteration:" + usersResponse.size());
followers.addAll(usersResponse);
cursor = usersResponse.getNextCursor();
counter++;
}
else {
System.out.println("enter any argument");
}
}
catch (TwitterException e) {
e.printStackTrace();
}
} while ((cursor) != 0);
for ( User user : followers) {
try {
red.write("Location> ");
red.write(user.getLocation());
red.write("\t");
red.write("Status location> ");
red.write(user.getStatus().getPlace().getCountry());
red.write("\t");
} catch(NullPointerException e) {
red.write("null found");
red.write("\t");
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
red.newLine();
}