简体   繁体   English

Android,Facebook登录按钮导致崩溃(SDK 4.0.0)

[英]Android, Facebook Login Button Causes Crash (SDK 4.0.0)

In my activity .xml file, I include the Facebook Login Button (from this documentation) 在我的活动.xml文件中,我包含了Facebook登录按钮(来自文档)

    <com.facebook.login.widget.LoginButton
    android:id="@+id/login_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="30dp"
    android:layout_marginBottom="30dp" />

Immediately I get a warning saying that 我马上得到一个警告说

The following classes could not be found:
    - com.facebook.login.widget.LoginButton

The documentation says to 文档说到

Add the button to your layout XML file with the full class name, com.facebook.widget.LoginButton 使用完整的类名com.facebook.widget.LoginButton将按钮添加到布局XML文件中

But changing that top line does nothing. 但改变顶线没有任何作用。 The app crashes immediately, without opening, and nothing is recorded in the log cat (testing on external device). 应用程序立即崩溃,无需打开,日志cat中没有记录任何内容(在外部设备上进行测试)。

Removing the button, or changing it to 删除按钮或将其更改为

    <Button
    android:id="@+id/login_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="30dp"
    android:layout_marginBottom="30dp" />

stops the crash, but this is my first time working with the Facebook SDK and don't know if the regular button will work. 停止崩溃,但这是我第一次使用Facebook SDK,不知道常规按钮是否有效。

Thank you in advance. 先感谢您。

Add FacebookSdk.sdkInitialize(getActivity().getApplicationContext()); 添加FacebookSdk.sdkInitialize(getActivity().getApplicationContext()); before inflating the view.. 在给视图充气之前..
- If this xml is used in activity, write above line before setContentView() - 如果在活动中使用此xml,请在setContentView()之前写入上面的行
- If this xml is used in fragment, write this line before inflater.inflate... - 如果在片段中使用此xml,请在inflater.inflate...之前写入此行inflater.inflate...

And, just ignore the warning shown in layout preview window 并且,只需忽略布局预览窗口中显示的警告

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM