请帮帮我!!! 我真的需要你的帮助来解决这个问题:
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) {}
}
我不知道是什么问题。第二天,我无法解决这个问题。如果你帮忙,我会很高兴的。
答案 0 :(得分:0)
首先尝试初始化Facebook SDK
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_main);
.....
}
答案 1 :(得分:0)
你应该把这两行:
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
紧随其后:
super.onCreate(savedInstanceState);
像这样:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
setContentView(R.layout.activity_main);
.....
}