Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoClassDefFoundError: com.facebook.android.Facebook

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?

like image 828
user983965 Avatar asked Apr 20 '12 18:04

user983965


4 Answers

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...)

like image 144
Matjaz Kristl Avatar answered Nov 18 '22 23:11

Matjaz Kristl


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.

like image 33
Emmanuel Avatar answered Nov 18 '22 22:11

Emmanuel


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.

like image 22
Gadenkan Avatar answered Nov 18 '22 23:11

Gadenkan


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.

like image 1
Kyle Clegg Avatar answered Nov 18 '22 23:11

Kyle Clegg