com.facebook.widget.loginbutton error in xml

Shikha Shah picture Shikha Shah · Oct 3, 2013 · Viewed 9.1k times · Source

I know as soon as I post this question on stackOverflow it is going to be marked as duplicate but trust me I have tried every possible solution discussed under the same topic in StackOverflow.

I am trying to add Facebook SDK in my project . After adding it under my project->properties->Android (then add facebook adk as library) , when i try to create my xml file and use it shows me red cross next to it and no matter what i do I am not able to make this error go away. Please help me..Anything help is appreciated!!

Answer

jimmithy picture jimmithy · Oct 3, 2013

The 'Unbound Prefix' error is due to having a custom namespace in your xml that is not accounted for.

You need to add another prefix to the top of your file. It should be similar to what I've wrote below, but with PREFIX replaced by the prefix you are using.

xmlns:*PREFIX*="http://schemas.android.com/apk/res-auto"

So, in the end, your file should look something like this:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fb="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">

    <com.facebook.widget.LoginButton
    android:id="@+id/connectWithFbButton"
    style="@style/com_facebook_loginview_default_style"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_gravity="center_horizontal"
    android:text="@string/connect_with_facebook"
    fb:login_text="@string/connect_with_facebook"
    fb:logout_text="Connecting with facebook" />

</LinearLayout>

In this example I've added the prefix 'fb' and I have referenced it when using the fields login_text and logout_text :)