I m trying to integrate the facebook in my app.I am using facebook example app downloaded from facebook as a reference(also generated the appId
and all this process on developer.facebook).I am little lazy so I do not want to go through all the code of facebook sdk.In simple words i just add the com_android_facebook
library project in my app, and also copy all the classes in facebook example app in my app except Example.java
Now i modify the MyActivity class look like Example.java class, means MyActivity now have all the code of Example class and also my main Activity.
and i change the layout of my app as
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textSize="22px"
android:textColor="#ff00ff"
android:gravity="center"
>
</TextView>
<com.android.facebook.LoginButton
android:id="@+id/login"
android:src="@drawable/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
/>
<Button android:id="@+id/uploadButton"
android:text="@string/upload"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:paddingLeft="20dp"
android:layout_margin="20dp"
/>
<Button android:id="@+id/requestButton"
android:text="@string/request"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:paddingLeft="20dp"
android:layout_margin="20dp"
/>
<Button android:id="@+id/postButton"
android:text="@string/post"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:paddingLeft="20dp"
android:layout_margin="20dp"
/>
<Button android:id="@+id/deletePostButton"
android:text="@string/delete"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:paddingLeft="20dp"
android:layout_margin="20dp"
/>
</RelativeLayout>
Now when i run my app i am getting there errors
10-14 00:58:37.786: ERROR/AndroidRuntime(3971): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.myapp/com.android.myapp.MyActivity}: android.view.InflateException: Binary XML file line #21: Error inflating class com.android.facebook.LoginButton
10-14 00:58:37.786: ERROR/AndroidRuntime(3971): Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class com.android.facebook.LoginButton
10-14 00:58:37.786: ERROR/AndroidRuntime(3971): Caused by: java.lang.ClassNotFoundException: com.android.facebook.LoginButton in loader dalvik.system.PathClassLoader@44c06850
Any help, suggestions are most welcome...
I also faced the same issue. I changed the main.xml from:
to (Current package is com.facebook.fbtest_simple):
As LoginButton is not part of FB standard library.
Initializing the Facebook SDK is what worked for me.
Easy one :
Looking for in the facebook src , you can go to this path:
..And see that there isn't nothing like LoginButton , then i can think that you are using an old tutorial or something like that.
As of version 3.0 of the Facebook SDK, the LoginButton is now available as part of the SDK as com.facebook.widget.LoginButton
See https://developers.facebook.com/docs/reference/android/3.0/LoginButton
Note that Facebook's own upgrade instructions here reference the wrong package, the LoginButton must be declared as com.facebook.widget.LoginButton, not com.facebook.LoginButton
There is no
LoginButton
in the main source of that SDK.It's available in the sample code only, so it just fails to load the unavailable class (
ClassNotFoundException
)...