Twitter4Jを使用してTwitterタイムラインを取得するために、Androidで次のコードを使用しています。しかし、Activity で Nullpointer Exception が発生していますか? 何か案が ?認証なしで Android で Twitter フィードを取得するための他の実用的なチュートリアルを提案することもできます。多くのことを試しましたが、ほとんどすべてがどこかで失敗しました。
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