无法在Android中使用Twitter4J库获取Twitter Feed

时间:2013-07-18 07:35:07

标签: android twitter

我在Android中使用以下代码来使用Twitter4J获取Twitter时间线。但我在活动中得到Nullpointer异常?任何的想法 ?您还可以建议任何其他工作教程,以便在没有身份验证的情况下获取Android Feed。尝试过很多,但几乎所有人都失败了。

public class TwitterTimelineActivity extends Activity {

String[] args;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tweet);

    Twitter twitter = new TwitterFactory().getInstance();
    try {
        List<Status> statuses;
        String user;
        if (args.length == 1) {
            user = args[0];
            statuses = twitter.getUserTimeline(user);
        } else {
            //user = twitter.verifyCredentials().getScreenName();
            user = "doubletree";
            statuses = twitter.getUserTimeline();
        }
        System.out.println("Showing @" + user + "'s user timeline.");
        for (Status status : statuses) {
            System.out.println("Timeline : " + "@" + status.getUser().getScreenName()
                    + " - " + status.getText());
        }
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get timeline: " + te.getMessage());
        System.exit(-1);
    }
}

}

获得以下例外:

07-18 13:31:17.525: E/AndroidRuntime(29810): FATAL EXCEPTION: main
07-18 13:31:17.525: E/AndroidRuntime(29810): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.itcuties.multicategoryrssreader/com.itcuties.multicategoryrssreader.TwitterTimelineActivity}: java.lang.NullPointerException
07-18 13:31:17.525: E/AndroidRuntime(29810):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
07-18 13:31:17.525: E/AndroidRuntime(29810):    at android.app.ActivityThread.startActivityNow(ActivityThread.java:1941)
07-18 13:31:17.525: E/AndroidRuntime(29810):    at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
07-18 13:31:17.525: E/AndroidRuntime(29810):    at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
07-18 13:31:17.525: E/AndroidRuntime(29810):    at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:705)
07-18 13:31:17.525: E/AndroidRuntime(29810):    at android.widget.TabHost.setCurrentTab(TabHost.java:369)
07-18 13:31:17.525: E/AndroidRuntime(29810):    at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:150)
07-18 13:31:17.525: E/AndroidRuntime(29810):    at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:560)
07-18 13:31:17.525: E/AndroidRuntime(29810):    at android.view.View.performClick(View.java:4223)
07-18 13:31:17.525: E/AndroidRuntime(29810):    at android.view.View$PerformClick.run(View.java:17275)
07-18 13:31:17.525: E/AndroidRuntime(29810):    at android.os.Handler.handleCallback(Handler.java:615)
07-18 13:31:17.525: E/AndroidRuntime(29810):    at android.os.Handler.dispatchMessage(Handler.java:92)
07-18 13:31:17.525: E/AndroidRuntime(29810):    at android.os.Looper.loop(Looper.java:137)
07-18 13:31:17.525: E/AndroidRuntime(29810):    at android.app.ActivityThread.main(ActivityThread.java:4898)
07-18 13:31:17.525: E/AndroidRuntime(29810):    at java.lang.reflect.Method.invokeNative(Native Method)
07-18 13:31:17.525: E/AndroidRuntime(29810):    at java.lang.reflect.Method.invoke(Method.java:511)
07-18 13:31:17.525: E/AndroidRuntime(29810):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
07-18 13:31:17.525: E/AndroidRuntime(29810):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775) 
07-18 13:31:17.525: E/AndroidRuntime(29810):    at dalvik.system.NativeStart.main(Native Method)
07-18 13:31:17.525: E/AndroidRuntime(29810): Caused by: java.lang.NullPointerException
07-18 13:31:17.525: E/AndroidRuntime(29810):    at com.itcuties.multicategoryrssreader.TwitterTimelineActivity.onCreate(TwitterTimelineActivity.java:24)
07-18 13:31:17.525: E/AndroidRuntime(29810):    at android.app.Activity.performCreate(Activity.java:5206)
07-18 13:31:17.525: E/AndroidRuntime(29810):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
07-18 13:31:17.525: E/AndroidRuntime(29810):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
07-18 13:31:17.525: E/AndroidRuntime(29810):    ... 18 more

0 个答案:

没有答案