107:错误输出类com.facebook.login.widget.LoginButton

时间:2016-03-01 08:05:02

标签: java android xml facebook android-fragments

我知道这是一个非常常见的问题,但是我已经阅读了所有堆栈溢出问题而没有找到答案。

我正在尝试使用通过Gradle添加的Facebook SDK 4.0.1集成Facebook登录按钮,但是我收到以下错误。

//这些是我得到的logcat错误。

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.virasatsolutions.www.donapp/com.virasatsolutions.www.donapp.Login1}: android.view.InflateException: Binary XML file line #24: Binary XML file line #107: Error inflating class com.facebook.login.widget.LoginButton
                                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                                   at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                   at android.os.Looper.loop(Looper.java:148)
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                                Caused by: android.view.InflateException: Binary XML file line #24: Binary XML file line #107: Error inflating class com.facebook.login.widget.LoginButton
                                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                                                                                   at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
                                                                                   at android.app.Activity.setContentView(Activity.java:2166)
                                                                                   at com.virasatsolutions.www.donapp.Login1.onCreate(Login1.java:54)
                                                                                   at android.app.Activity.performCreate(Activity.java:6237)
                                                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                                   at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                   at android.os.Looper.loop(Looper.java:148) 
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                                Caused by: android.view.InflateException: Binary XML file line #107: Error inflating class com.facebook.login.widget.LoginButton
                                                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:645)
                                                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
                                                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                                                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
                                                                                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                                                                                   at android.view.LayoutInflater.parseInclude(LayoutInflater.java:971)
                                                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:831)
                                                                                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                                                   at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
                                                                                   at android.app.Activity.setContentView(Activity.java:2166) 
                                                                                   at com.virasatsolutions.www.donapp.Login1.onCreate(Login1.java:54) 
                                                                                   at android.app.Activity.performCreate(Activity.java:6237) 
                                                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                                   at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                   at android.os.Looper.loop(Looper.java:148) 
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                                Caused by: java.lang.reflect.InvocationTargetException
                                                                                   at java.lang.reflect.Constructor.newInstance(Native Method)
                                                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:619)
                                                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
                                                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                                                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                                                                                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                                                                                   at android.view.LayoutInflater.parseInclude(LayoutInflater.java:971) 
                                                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:831) 
                                                                                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
                                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                                                   at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
                                                                                   at android.app.Activity.setContentView(Activity.java:2166) 
                                                                                   at com.virasatsolutions.www.donapp.Login1.onCreate(Login1.java:54) 
                                                                                   at android.app.Activity.performCreate(Activity.java:6237) 
                                                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                                   at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                   at android.os.Looper.loop(Looper.java:148) 
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                                Caused by: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.
                                                                                   at com.facebook.internal.Validate.sdkInitialized(Validate.java:136)
                                                                                   at com.facebook.AccessTokenTracker.<init>(AccessTokenTracker.java:55)
                                                                                   at com.facebook.login.widget.LoginButton$2.<init>(LoginButton.java:561)
                                                                                   at com.facebook.login.widget.LoginButton.configureButton(LoginButton.java:561)
                                                                                   at com.facebook.FacebookButtonBase.<init>(FacebookButtonBase.java:69)
                                                                                   at com.facebook.login.widget.LoginButton.<init>(LoginButton.java:200)
                                                                                   at java.lang.reflect.Constructor.newInstance(Native Method) 
                                                                                   at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
                                                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
                                                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                                                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                                                                                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                                                                                   at android.view.LayoutInflater.parseInclude(LayoutInflater.java:971) 
                                                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:831) 
                                                                                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
                                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                                                                                   at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393) 
                                                                                   at android.app.Activity.setContentView(Activity.java:2166) 
                                                                                   at com.virasatsolutions.www.donapp.Login1.onCreate(Login1.java:54) 
                                                                                   at android.app.Activity.performCreate(Activity.java:6237) 
                                                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                                   at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                   at android.os.Looper.loop(Looper.java:148) 
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
03-01 11:22:04.847 2474-2474/? I/Process: Sending signal. PID: 2474 SIG: 9

//这是我的带有依赖关系的gradel文件

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    repositories
            {
                mavenCentral()
            }


    defaultConfig {
        applicationId "com.virasatsolutions.www.donapp"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }


}

//依赖项文件

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.google.android.gms:play-services-identity:8.4.0'
    compile 'com.paypal.sdk:paypal-android-sdk:2.13.1'
    compile 'com.facebook.android:facebook-android-sdk:4.+'

    compile 'com.google.android.gms:play-services-appindexing:8.4.0'
}

//这是我的布局文件,其中将提供facebook登录按钮

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".Login1"
    tools:showIn="@layout/activity_login1"
    android:background="#1F874E">


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="SIGN IN"
        android:id="@+id/textView8"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:textColor="#FFFFFF"
        android:textSize="20dp"
        android:textStyle="bold"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Email"
        android:id="@+id/textView9"
        android:layout_marginTop="47dp"
        android:textColor="#FFFFFF"
        android:layout_below="@+id/textView8"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
        android:ems="10"
        android:id="@+id/email1"
        android:layout_below="@+id/textView9"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Password"
        android:id="@+id/textView10"
        android:layout_below="@+id/email1"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="44dp"
        android:textColor="#FFFFFF"/>

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:ems="10"
        android:id="@+id/password6"
        android:layout_below="@+id/textView10"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SIGN IN"
        android:id="@+id/signin"
        android:onClick="OnClick"
        android:layout_below="@+id/password6"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignRight="@+id/password6"
        android:layout_alignEnd="@+id/password6" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="SIGN UP"
        android:id="@+id/signup"
        android:onClick="OnClick"
        android:layout_below="@+id/signin"
        android:layout_marginTop="47dp"
        android:layout_alignRight="@+id/signin"
        android:layout_alignEnd="@+id/signin"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />



    <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_below="@+id/signup"
        android:layout_toRightOf="@+id/textView9"
        android:layout_toEndOf="@+id/textView9"
        android:width="20dp"/>



</RelativeLayout>

//这是我的login.java文件,其中facebook功能是他们的

//这里我使用了片段活动,因为片段不支持数据库

public class Login1 extends FragmentActivity {
DatabaseHelper helper=new DatabaseHelper(this);
    private CallbackManager mCallbackManager;
    private FacebookCallback<LoginResult> mCallback=new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            AccessToken accessToken=loginResult.getAccessToken();
            Profile profile = Profile.getCurrentProfile();


        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException error) {

        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login1);




        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
        FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
        mCallbackManager =CallbackManager.Factory.create();
    }


    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        return inflater.inflate(R.layout.content_login1, container, false);


    }



    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        super.onActivityResult(requestCode, resultCode, data);
        mCallbackManager.onActivityResult(requestCode, resultCode, data);
    }
    private FacebookSdk getActivity() {
        return null;
    }


    public void OnClick(View view)
    {
        if(view.getId()==R.id.signin)
        {
            EditText email=(EditText)findViewById(R.id.email1);
            String emailstr1 = email.getText().toString();
            EditText pass=(EditText)findViewById(R.id.password6);
            String passstr=pass.getText().toString();
           String password= helper.searchPass(emailstr1);
            if(passstr.equals(password))
            {
                Intent i=new Intent(Login1.this,MainActivity.class);
                startActivity(i);
            }
            else
            {
                Toast temp = Toast.makeText(Login1.this, "Email and Password dont match", Toast.LENGTH_SHORT);
                temp.show();
            }

        }
        if (view.getId()==R.id.signup)
        {
            Intent i=new Intent(Login1.this,sign_up.class);
            startActivity(i);
        }

    }


}

2 个答案:

答案 0 :(得分:0)

在setcontentView()之前初始化facebook sdk。

答案 1 :(得分:0)

FacebookSdk.sdkInitialize(this); setContentView(R.layout.activity_login2);