简体   繁体   中英

Android, Facebook Login Button Causes Crash (SDK 4.0.0)

In my activity .xml file, I include the Facebook Login Button (from this documentation)

    <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

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

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.

Thank you in advance.

Add FacebookSdk.sdkInitialize(getActivity().getApplicationContext()); before inflating the view..
- If this xml is used in activity, write above line before setContentView()
- If this xml is used in fragment, write this line before inflater.inflate...

And, just ignore the warning shown in layout preview window

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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