I am trying to create an application that will allow users to register through their Facebook accounts. I wanted to use the new Facebook SDK 4.1.2 via eclipse. To use the new SDK in eclipse, I completed this tutorial . Now I can remove all errors from the facebook SDK file without eclipse. Then I started following these steps to integrate FB into the sample application using the new SDK.
I continued:
MainActivity :
import android.os.Bundle; import android.support.v4.app.FragmentActivity; import com.facebook.CallbackManager; import com.facebook.FacebookSdk; public class MainActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FacebookSdk.sdkInitialize(getApplicationContext()); if (savedInstanceState == null) { getFragmentManager() .beginTransaction() .add(R.id.fragmentParentViewGroup, new FacebookFragment()) .commit(); } } }
activity_main.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/fragmentParentViewGroup" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MyActivity" tools:ignore="MergeRootFrame" />
Facebook snippet:
import android.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.facebook.CallbackManager; import com.facebook.FacebookCallback; import com.facebook.FacebookException; import com.facebook.FacebookSdk; import com.facebook.login.LoginResult; import com.facebook.login.widget.LoginButton; public class FacebookFragment extends Fragment{ CallbackManager callbackManager; @Override public View onCreateView(LayoutInflater inflater, ViewGroup parentViewGroup, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.facebook_fragment, parentViewGroup, false); FacebookSdk.sdkInitialize(getActivity()); callbackManager = CallbackManager.Factory.create(); LoginButton loginButton = (LoginButton) rootView.findViewById(R.id.login_button); loginButton.setReadPermissions("user_friends");
Facebook_fragment.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FFFFFF"> <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" /> </RelativeLayout>
manifesto:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.facbooksdk4test" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /> <uses-permission android:name="android.permission.INTERNET" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.facbooksdk4test.MainActivity" android:label="@string/app_name" android:theme="@android:style/Theme.Translucent.NoTitleBar" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id" /> <activity android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:label="@string/app_name" android:theme="@android:style/Theme.Translucent.NoTitleBar" /> </application> </manifest>
After doing all of the above, I still get initialization errors. Logcat report:
06-01 15:23:41.670: E/AndroidRuntime(23571): FATAL EXCEPTION: main 06-01 15:23:41.670: E/AndroidRuntime(23571): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.facbooksdk4test/com.facbooksdk4test.MainActivity}: android.view.InflateException: Binary XML file line
I am not sure where I am going wrong, or what needs to be done to fix the problems. Please suggest me what needs to be done to fix the same.
android logging facebook
kittu88 Jun 01 '15 at 10:11 2015-06-01 10:11
source share