android - Facebook SDK V4.1.0 LoginButton仅在Android小于5的启动时崩溃

android - Facebook SDK V4.1.0 LoginButton仅在Android小于5的启动时崩溃,第1张

启动时应用程序崩溃

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.appandgo.appyvent/com.appandgo.appyvent.newuser.NDWelcomeActivity}: android.view.InflateException: Binary XML file line #34: Error inflating class com.facebook.login.widget.LoginButton
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
        at android.app.ActivityThread.access0(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 #34: Error inflating class com.facebook.login.widget.LoginButton
        at android.view.LayoutInflater.createView(LayoutInflater.java:620)
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 com.appandgo.appyvent.newuser.NDWelcomeFragment.onCreateView(NDWelcomeFragment.java:131)
        at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
        at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
        at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
        at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:548)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
        at android.app.Activity.performStart(Activity.java:5241)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2157)

我需要更新到4.1.0版

所以在我的Grandle中我补充道:

compile 'com.facebook.android:facebook-android-sdk:4.1.0'

然后我在Fragment中的代码是:

public View onCreateView(LayoutInflater inflater,
         ViewGroup container,  Bundle savedInstanceState) {



    FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
    v = inflater.inflate(R.layout.welcome_fragment, container, false);

    LoginButton authButton = (LoginButton) v.findViewById(R.id.login_button);
    authButton.setFragment(this);

    authButton.setReadPermissions(Arrays.asList("public_profile", "user_birthday", "email", "user_friends"));
    authButton.registerCallback(mCallbackManager, mCallBack);


    });

还添加一个Oncreate方法并添加FacebookSdk.sdkInitialize

我的XML:

<com.facebook.login.widget.LoginButton
    xmlns:fb="http://schemas.android.com/apk/res-auto"
    android:id="@ id/login_button"
    android:layout_width="280dp"
    android:layout_height="50dp"
    android:layout_centerHorizontal="true"
    android:gravity="center"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="100dp"
    android:paddingTop="15dp"
    android:paddingBottom="15dp"
    android:background="@drawable/facebook_button"
    />

我的Manifast也有正确的配置。

我无法弄清楚其他帖子中的其他答案没有帮助。

我还尝试将SDK添加为项目,但仍然遇到了同样的崩溃。

我也尝试过以下(在oncreateView中):

FacebookSdk.sdkInitialize(getActivity().getApplicationContext());

    if (v != null)
    {
        ViewGroup parent = (ViewGroup)v.getParent();
        if (parent != null)
            parent.removeView(v);
    }
    try {
        v = inflater.inflate(R.layout.welcome_fragment, container, false);
    } catch (InflateException e) {
        // the is already there just return it
    }

然后inflater返回null。如果我删除了Facebook登录按钮,则V对象不为空

最佳答案:

0 个答案:

没有答案
本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复