Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

how to integrate facebook in android using facebook sdk 4.10

Hi when I am using Login button in my XML, I am getting exception like "The following classes could not be instantiated: - com.facebook.login.widget.LoginButton (Open Class, Show Error Log)". how can I solve this.and I need to display login page how can I do this?

and this is my XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.facebooklogin.MainActivity$PlaceholderFragment" >

    <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" />   
</Relative Layout>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is xml code of fb sdk example like this

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:facebook="http://schemas.android.com/apk/res-auto"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:background="#FFF"
        >
    <LinearLayout android:orientation="vertical"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:background="#FFF"
                  android:id="@+id/main_ui_container">
        <com.facebook.login.widget.LoginButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:layout_gravity="center_horizontal"
            facebook:confirm_logout="false"
            facebook:tooltip_mode="never_display"
            />
        <LinearLayout
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:gravity="center_horizontal"
                android:orientation="vertical"
            >
            <TextView
                    android:id="@+id/greeting"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:layout_gravity="center"
                    android:textColor="#333"
                    android:textSize="18sp"/>
            <com.facebook.login.widget.ProfilePictureView
                    android:id="@+id/profilePicture"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:gravity="center_horizontal"
                    android:layout_marginBottom="10dp"
                    facebook:preset_size="normal"/>
            <Button
                    android:id="@+id/postStatusUpdateButton"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="Post Status Update"
                    />
            <Button
                    android:id="@+id/postPhotoButton"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="Post Photo"
                    />

        </LinearLayout>
    </LinearLayout>

</LinearLayout>

And Mainfeast file like this

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.facebook.samples.hellofacebook"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="9"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <application android:label="@string/app_name"
                 android:icon="@drawable/icon"
                 android:theme="@android:style/Theme.NoTitleBar"
            >
        <activity android:name=".HelloFacebookSampleActivity"
                  android:label="@string/app_name"
                  android:windowSoftInputMode="adjustResize">
            <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:theme="@android:style/Theme.Translucent.NoTitleBar"
                  android:label="@string/app_name" />
        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
        <meta-data android:name="com.facebook.sdk.ApplicationName"
                   android:value="@string/facebook_app_name" />
        <provider android:authorities="com.facebook.app.FacebookContentProvider355198514515820"
                  android:name="com.facebook.FacebookContentProvider"
                  android:exported="true"/>
        <receiver android:name="com.facebook.samples.hellofacebook.HelloFacebookBroadcastReceiver">
            <intent-filter>
                <action android:name="com.facebook.platform.AppCallResultBroadcast" />
            </intent-filter>
        </receiver>
    </application>
</manifest>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...