Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Twitter4j giving error NoClassDefFoundError: twitter4j.TwitterFactory

I am making an app that communicates with Twitter to post a tweet. My problem is that when compile my code, I get the error message:

NoClassDefFoundError: twitter4j.TwitterFactory

Here is the code that post's the tweet via an onClickListener:

post.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            Twitter twitter = new TwitterFactory().getInstance();  
            AccessToken a = new AccessToken("****", "****");
            twitter.setOAuthConsumer("****", "****");
            twitter.setOAuthAccessToken(a); 
            try {
                twitter.updateStatus("If you're reading this on Twitter, it worked!");
            } catch (TwitterException e) {
                e.printStackTrace();
            }   
        }
    });

Here is what I got in my logcat:

04-04 10:27:51.330: E/AndroidRuntime(12547): FATAL EXCEPTION: main
04-04 10:27:51.330: E/AndroidRuntime(12547): java.lang.NoClassDefFoundError: twitter4j.TwitterFactory
04-04 10:27:51.330: E/AndroidRuntime(12547):    at com.bintuu.updater.TwitterClass$3.onClick(TwitterClass.java:107)
04-04 10:27:51.330: E/AndroidRuntime(12547):    at android.view.View.performClick(View.java:2485)
04-04 10:27:51.330: E/AndroidRuntime(12547):    at android.view.View$PerformClick.run(View.java:9080)
04-04 10:27:51.330: E/AndroidRuntime(12547):    at android.os.Handler.handleCallback(Handler.java:587)
04-04 10:27:51.330: E/AndroidRuntime(12547):    at android.os.Handler.dispatchMessage(Handler.java:92)
04-04 10:27:51.330: E/AndroidRuntime(12547):    at android.os.Looper.loop(Looper.java:130)
04-04 10:27:51.330: E/AndroidRuntime(12547):    at android.app.ActivityThread.main(ActivityThread.java:3683)
04-04 10:27:51.330: E/AndroidRuntime(12547):    at java.lang.reflect.Method.invokeNative(Native Method)
04-04 10:27:51.330: E/AndroidRuntime(12547):    at java.lang.reflect.Method.invoke(Method.java:507)
04-04 10:27:51.330: E/AndroidRuntime(12547):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-04 10:27:51.330: E/AndroidRuntime(12547):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-04 10:27:51.330: E/AndroidRuntime(12547):    at dalvik.system.NativeStart.main(Native Method)
like image 473
Buneme Kyakilika Avatar asked Feb 21 '23 22:02

Buneme Kyakilika


2 Answers

try renaming the "lib" folder name to "libs". That solved a similar issue for me, check here: https://github.com/ddewaele/AndroidTwitterSample/issues/2

like image 83
PakitoV Avatar answered Mar 30 '23 00:03

PakitoV


I've found the solution now. The problem was that I was using a very old version of Twitter4j, and in my libs folder, there were multiple jars with identical names. I have now fixed those problems and it is now working perfectly.

like image 21
Buneme Kyakilika Avatar answered Mar 30 '23 00:03

Buneme Kyakilika