views:

400

answers:

2

Hello Guys,

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

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

You need to add apache http components to your classpath

Guillaume
I have added the twitter4j-httpclient-support-2.1.3-SNAPSHOT.jar as well as the httpclient-4.0.1.jar, but this hasn't changed anything. :/
Philipp Andre
Try using DefaultHttpClient in a simple class to make sure it's actually on your project's classpath
Guillaume
DefaultHttpClient client = new DefaultHttpClient(); executes without any exceptions.
Philipp Andre
Could you post a zipped, slimmed down version of your eclipse project?
Guillaume
A: 

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.

Andreas_D
thanks! but this isn't a plugin project :)
Philipp Andre