2015-05-05 39 views
1

嗨,當我在我的XML中使用登錄按鈕時,出現異常,例如「以下類無法實例化: - com.facebook.login.widget.LoginButton打開類,顯示錯誤日誌)「。我該如何解決這個問題。我需要顯示登錄頁面,我該怎麼做?如何在Facebook中使用facebook sdk集成facebook 4.10

,這是我的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> 
+0

退房FB SDK示例XML代碼:HTTP:/ /www.codeproject.com/Articles/820929/A-beginners-Guide-to-Social-Network-Integration-in –

+0

檢查[this](https://developers.facebook.com/quick啓動/?平臺= android)也嘗試在真實設備上運行它。 – Skynet

+1

發佈您的代碼和xml – Soham

回答

0

這是這樣

<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> 

而且Mainfeast文件中像這樣

<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> 
+0

謝謝你......它完美地工作 –

+0

@vinode kumar your welcome – Singhak