简体   繁体   中英

How can i use args.length control in android

I'm trying to develop an app using twitter4j and fabric. There is example which i can call Listing followers id but i don't know how i can use arg.length in android. Android studio can not resolve args argument. What can i use instead of it for this code ?

try {
                Twitter twitter = new TwitterFactory().getInstance();
                long cursor = -1;
                IDs ids;

                System.out.println("Listing followers's ids.");
                do {
                    if (0 < args.length) {
                        ids = twitter.getFollowersIDs(args[0], cursor);
                    } else {
                        ids = twitter.getFollowersIDs(cursor);
                    }
                    for (long id : ids.getIDs()) {
                        System.out.println(id);
                    }
                } while ((cursor = ids.getNextCursor()) != 0);
                System.exit(0);
            } catch (TwitterException te) {
                te.printStackTrace();
                System.out.println("Failed to get followers' ids: " + te.getMessage());
                System.exit(-1);
            }

I solved the problem. At twitter4j documentation( http://twitter4j.org/javadoc/twitter4j/api/FriendsFollowersResources.html ) getFollowersIDs is overloaded. So we can use long userId instead of args.

try {
                Twitter twitter = new TwitterFactory().getInstance();
                long cursor = -1;
                IDs ids;

                System.out.println("Listing followers's ids.");
                do {
                    if (0 < userId) {
                        ids = twitter.getFollowersIDs(userId, cursor);
                    } else {
                        ids = twitter.getFollowersIDs(cursor);
                    }
                    for (long id : ids.getIDs()) {
                        System.out.println(id);
                    }
                } while ((cursor = ids.getNextCursor()) != 0);
                System.exit(0);
            } catch (TwitterException te) {
                te.printStackTrace();
                System.out.println("Failed to get followers' ids: " + te.getMessage());
                System.exit(-1);
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM