Android的Facebook的LoginButton类未找到 [英] Android Facebook LoginButton class not found
问题描述
我导入Facebook的SDK(v3.21.1)模块到Android的工作室(V1.0.2),并在尝试创建 com.facebook.widget.LoginButton
如文档中建议 的有以下code:
I imported the Facebook SDK (v3.21.1) module into Android Studio (v1.0.2), and am trying to create a LoginActivity with com.facebook.widget.LoginButton
as suggested in the documentation with the following code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.facebook.widget.LoginButton
android:id="@+id/authButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
/>
</LinearLayout>
不过,在Android的工作室渲染说,它无法找到LoginButton类:
However, the renderer in Android Studio says that it can't find the LoginButton class:
以下类不能被找到: - com.facebook.widget.LoginButton
我知道一个事实,即类的存在,因为我可以打开该文件,并且它在正确的位置:
I know for a fact that the class exists because I can open the file, and it is in the correct location:
我知道它的存在,而是要证明到Android Studio中确实如此,我试图创建一个类,如渲染建议,并收到以下错误:
I know it exists, but to prove to Android Studio that it does, I tried creating a class, as suggested in the renderer, and receive the following error:
我试过下面还有:
- 重新导入Facebook的SDK(删除/重新导入Facebook的模块:删除物理文件等)
- 重新打开我的项目
- 在重新开放的Android工作室
- 建设项目
没有什么工作。什么是可笑的是,即使是自动完成可以看到类:
Nothing works. What's ridiculous is that even the auto-complete can see the class:
修改:我试过只是运行在模拟器中的应用程序,忽略了渲染错误,并且应用程序崩溃并出现以下错误:
Edit: I tried just running the app in the emulator, ignoring the rendering error, and the app crashes with the following error:
12-31 03:47:15.593 2824-2824/com.test.playground E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.test.playground, PID: 2824
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.playground/com.test.playground.LoginActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class com.facebook.widget.LoginButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class com.facebook.widget.LoginButton
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
at android.app.Activity.setContentView(Activity.java:1929)
at com.test.playground.LoginActivity.onCreate(LoginActivity.java:15)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.facebook.widget.LoginButton" on path: DexPathList[[zip file "/data/app/com.test.playground-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.test.playground-2, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.view.LayoutInflater.createView(LayoutInflater.java:559)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
at android.app.Activity.setContentView(Activity.java:1929)
at com.test.playground.LoginActivity.onCreate(LoginActivity.java:15)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
再次类的确实存在的,它只是似乎是Android的Studio无法找到它。这个类是可见的项目目录下 com.faceook.widget.LoginButton
...我不知道我错过了什么。我一直在试图找出了这一点,几个小时,没有什么工作。
Again, the class does exist, it just seems that Android Studio can't find it. The class is viewable in the project directory under com.faceook.widget.LoginButton
... I don't know what I'm missing. I've been trying to figure this out for hours and nothing is working.
推荐答案
你有没有整合Facebook的SDK到你的项目?检查 build.gradle
你的模块,并确保Facebook的SDK是依赖关系。如果没有,添加它和摇篮同步,然后重试。
Have you integrated the Facebook SDK into your project? Check the build.gradle
of your module and make sure that Facebook SDK is in dependencies. If not, add it and sync with Gradle and then try again.
在Facebook的模块应该被添加到依赖于 build.gradle
使用它的项目:
The Facebook module should be added to the dependencies in build.gradle
of the project that uses it:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':facebook')
}
同时,Facebook的模块应在 settings.gradle
输入:
include ':app', ':facebook'
这篇关于Android的Facebook的LoginButton类未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!