eclipse java.lang.NoClassDefFoundError: com.facebook.android.Facebook
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10251245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.NoClassDefFoundError: com.facebook.android.Facebook
提问by user983965
I keep getting the error java.lang.NoClassDefFoundError: com.facebook.android.Facebook when running my application.
运行我的应用程序时,我不断收到错误 java.lang.NoClassDefFoundError: com.facebook.android.Facebook 。
This occurs when calling:
调用时会发生这种情况:
facebook = new Facebook(APP_ID);
脸书 = 新脸书(APP_ID);
Addtional error message:
附加错误信息:
Could not find class 'com.facebook.android.Facebook', referenced from method com.example.example1.ShareOnFacebook.onCreate
找不到从方法 com.example.example1.ShareOnFacebook.onCreate 引用的类“com.facebook.android.Facebook”
I have add the facebook .jar file via Referenced libraries in Eclipse.
我已经通过 Eclipse 中的引用库添加了 facebook .jar 文件。
Has anyone encountered/solve this problem?
有没有人遇到/解决过这个问题?
回答by Matjaz Kristl
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"
只需转到 Project / Properties / Java Build Path / Order and Export 并单击 jar 的复选框。这会将 jar 设置为“已导出”。您可以在 .classparh 文件中验证这一点:classpathentry Export="true" kind="lib" path="/my-jars/facebook-android-sdk-1.2.1.jar"
Don't forget to clean your project after that (Project / Clean...)
之后不要忘记清理您的项目(项目/清理...)
回答by Emmanuel
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.
我听说使用最新的 ADT,您需要将库文件夹命名为“libs”而不是“lib”。但这对我不起作用。
So instead I had to resort to moving my jar file into the "assets" folder. That fixed my problem.
所以我不得不求助于将我的 jar 文件移动到“资产”文件夹中。那解决了我的问题。
Completely retarded if you ask me.
如果你问我,完全是迟钝的。
回答by Gadenkan
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.
我也一直遇到这个问题,“库项目”(应该包含 com_facebook_android.jar)根本没有反映在“包资源管理器”中。但它很容易解决。
右键单击项目>属性>Android>库->删除添加的facebook库项目->应用。然后再次添加facebook 库项目并单击应用。这次“库项目”将出现在右侧的包资源管理器中。
回答by Kyle Clegg
Have you recently updated your ADT or Android SDK? Try deleting the reference to the facebook library or facebook jar and re-adding it.
您最近是否更新了 ADT 或 Android SDK?尝试删除对 facebook 库或 facebook jar 的引用并重新添加它。
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.
他们在最新的 ADT 更新中改变了处理外部库引用的方式,并且它从我的大量项目中消失了。 删除引用并重新添加它们似乎可以解决问题。
回答by cristianorbs
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.
一个对我有用的解决方案:我项目中的 android-support-v4.jar 文件与 facebook 项目中的版本不同。所以我将 facebook 的支持库复制到我的项目库文件夹中,它就像一个魅力。