java.lang.NoClassDefFoundError: com.facebook.andro

2020-02-14 04:25发布

问题:

I keep getting the error java.lang.NoClassDefFoundError: com.facebook.android.Facebook when running my application.

This occurs when calling:

facebook = new Facebook(APP_ID);

Addtional error message:

Could not find class 'com.facebook.android.Facebook', referenced from method com.example.example1.ShareOnFacebook.onCreate

I have add the facebook .jar file via Referenced libraries in Eclipse.

Has anyone encountered/solve this problem?

回答1:

Just go to Project / Properties / Java Build Path / Order and Export and click on jar's checkbox. This will set jar as "exported". You can verify this in .classparh file: classpathentry exported="true" kind="lib" path="/my-jars/facebook-android-sdk-1.2.1.jar"

Don't forget to clean your project after that (Project / Clean...)



回答2:

I heard that with the latest ADT you need to name your library folder "libs" and not "lib". But that didn't work for me.

So instead I had to resort to moving my jar file into the "assets" folder. That fixed my problem.

Completely retarded if you ask me.



回答3:

I keep getting this issue too, the "Library Projects" (which should contain the com_facebook_android.jar) is not reflected in the "Package explorer" at all. But It is easily solved.
Right click on project>Properties>Android> Library -> remove the facebook library project added -> apply. Then add the facebook library project again and click apply. This time "Library Projects" will come up in your Package Explorer on the right side.



回答4:

Have you recently updated your ADT or Android SDK? Try deleting the reference to the facebook library or facebook jar and re-adding it.

They changed the way they handle external libraries references in the latest ADT updates, and it's thrown off a ton of my projects. Deleting the references and re-adding them seems to do the trick.



回答5:

A solution that worked for me: the android-support-v4.jar file inside my project had a different version from the one inside facebook's project. So I copied facebook's support lib to my project libs folder and it worked like a charm.