Урмат Тилеков Урмат Тилеков - 1 month ago 34
Android Question

Why I got this Error android.view.InflateException ... Binary XML file line #12 ... #25: Error inflating class com.facebook.login.widget.LoginButton?

Please help me!!!
I really need your help to solve this problem:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fblogin.MainActivity}: android.view.InflateException: Binary XML file line #24: Binary XML file line #12: Error inflating class com.facebook.login.widget.LoginButton


AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />

<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />

<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="@string/facebook_app_id" />
</intent-filter>
</activity>
</application>


build.gradle

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.facebook.android:facebook-android-sdk:4.16.0'
}


content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.urma....MainActivity"
tools:showIn="@layout/activity_main">

<com.facebook.login.widget.LoginButton
android:id="@+id/facebook_button_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"/>




MainActivity.java

public class MainActivity extends FragmentActivity implements FacebookCallback<LoginResult>{

private static final String TAG = "MainActivity";

LoginButton buttonLogin;
CallbackManager callbackManager;

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

FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);

callbackManager = CallbackManager.Factory.create();
buttonLogin = (LoginButton) findViewById(R.id.facebook_button_login);
buttonLogin.setReadPermissions("email", "user_friends");
buttonLogin.registerCallback(callbackManager, this);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.i(TAG, "onActivityResult: " + resultCode);
}

@Override
public void onSuccess(LoginResult loginResult) {
Log.i(TAG, "onSuccess: AccessToken " + loginResult.getAccessToken()
+ "Granted: " + loginResult.getRecentlyGrantedPermissions()
+" Denied: " + loginResult.getRecentlyDeniedPermissions());
}

@Override
public void onCancel() {}

@Override
public void onError(FacebookException error) {}
}


I do not know what is the problem. For the second day, I can not solve this. I would be very happy if you help.

Answer

try to initialize the Facebook SDK first

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_main);
.....
}