Twitter4J 在 TwitterFactory 中抛出异常

发布于 2024-09-03 13:40:50 字数 1871 浏览 4 评论 0原文

我正在尝试通过 oauth 访问 twitter。因此,我注册了我的应用程序,下载了 Twitter4j,在我的 Eclipse-Project 中添加了 jar,然后尝试执行以下代码:

Twitter twitter = new TwitterFactory().getOAuthAuthorizedInstance("[key]","[secretKey]");
RequestToken requestToken = twitter.getOAuthRequestToken();
System.out.println(requestToken.getAuthorizationURL());

但它引发了以下异常:

[Sat May 29 11:19:11 CEST 2010]Using class twitter4j.internal.logging.StdOutLoggerFactory as logging factory.
[Sat May 29 11:19:11 CEST 2010]Use twitter4j.internal.http.alternative.HttpClientImpl as HttpClient implementation.
Exception in thread "main" java.lang.AssertionError: java.lang.reflect.InvocationTargetException
    at twitter4j.internal.http.HttpClientFactory.getInstance(HttpClientFactory.java:71)
    at twitter4j.internal.http.HttpClientWrapper.<init>(HttpClientWrapper.java:59)
    at twitter4j.http.OAuthAuthorization.init(OAuthAuthorization.java:83)
    at twitter4j.http.OAuthAuthorization.<init>(OAuthAuthorization.java:74)
    at twitter4j.TwitterFactory.getOAuthAuthorizedInstance(TwitterFactory.java:112)
    at MainProgram.main(MainProgram.java:18)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at twitter4j.internal.http.HttpClientFactory.getInstance(HttpClientFactory.java:65)
    ... 5 more
Caused by: java.lang.NoClassDefFoundError: org/apache/http/impl/client/DefaultHttpClient
    at twitter4j.internal.http.alternative.HttpClientImpl.<init>(HttpClientImpl.java:63)
    ... 10 more

我目前无法弄清楚为什么......你能给出我一些建议?

此致 菲利普

i'm trying to access twitter via oauth. Therefore, i registered my app, downloaded Twitter4j, added the jars in my Eclipse-Project, and then tried to execute the following code:

Twitter twitter = new TwitterFactory().getOAuthAuthorizedInstance("[key]","[secretKey]");
RequestToken requestToken = twitter.getOAuthRequestToken();
System.out.println(requestToken.getAuthorizationURL());

But it raises the following exception:

[Sat May 29 11:19:11 CEST 2010]Using class twitter4j.internal.logging.StdOutLoggerFactory as logging factory.
[Sat May 29 11:19:11 CEST 2010]Use twitter4j.internal.http.alternative.HttpClientImpl as HttpClient implementation.
Exception in thread "main" java.lang.AssertionError: java.lang.reflect.InvocationTargetException
    at twitter4j.internal.http.HttpClientFactory.getInstance(HttpClientFactory.java:71)
    at twitter4j.internal.http.HttpClientWrapper.<init>(HttpClientWrapper.java:59)
    at twitter4j.http.OAuthAuthorization.init(OAuthAuthorization.java:83)
    at twitter4j.http.OAuthAuthorization.<init>(OAuthAuthorization.java:74)
    at twitter4j.TwitterFactory.getOAuthAuthorizedInstance(TwitterFactory.java:112)
    at MainProgram.main(MainProgram.java:18)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at twitter4j.internal.http.HttpClientFactory.getInstance(HttpClientFactory.java:65)
    ... 5 more
Caused by: java.lang.NoClassDefFoundError: org/apache/http/impl/client/DefaultHttpClient
    at twitter4j.internal.http.alternative.HttpClientImpl.<init>(HttpClientImpl.java:63)
    ... 10 more

I currently can't figure out why ... can you please give me some suggestions?

Best regards
Philipp

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独自←快乐 2024-09-10 13:40:50
Caused by: java.lang.NoClassDefFoundError: org/apache/http/impl/client/DefaultHttpClient

您需要将 apache http 组件添加到您的类路径中

Caused by: java.lang.NoClassDefFoundError: org/apache/http/impl/client/DefaultHttpClient

You need to add apache http components to your classpath

智商已欠费 2024-09-10 13:40:50

因为我读到了“eclipse 项目” - 如果这实际上是一个插件/rcp 项目,并且您的库驻留在其他插件中,那么您必须通过 plugin.xml 导出所需的包,否则将导致 NoClassDefFound 错误。

For I read 'eclipse project' - if this is actually a plugin/rcp project and your libraries reside in other plugins, then you have to export the required packages via plugin.xml, otherwise it will result in NoClassDefFound errors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文