没有找到Android Facebook LoginButton类 [英] Android Facebook LoginButton class not found

查看:106
本文介绍了没有找到Android Facebook LoginButton类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Facebook SDK(v3.21.1)模块导入Android Studio(v1.0.2),并尝试使用创建一个LoginActivity com.facebook.widget.LoginButton 如建议的在文档中与以下代码:

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 Studio中的渲染器表示找不到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模块:删除物理文件等)

  • Re - 打开我的项目

  • 重新打开Android Studio

  • 构建项目

  • Re-importing the Facebook SDK (deleting/re-importing the Facebook module: deleting the physical files, etc)
  • Re-opening my project
  • Re-opening Android Studio
  • Building the project

无效。可笑的是,即使自动完成也可以看到类:

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处于依赖关系。如果没有,添加它并与Gradle同步,然后再次尝试。

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

As well, the Facebook module should be imported in settings.gradle:

include ':app', ':facebook'

这篇关于没有找到Android Facebook LoginButton类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆