当我在XML中使用“登录”按钮时,我得到的异常就是“以下类无法实例化: - com.facebook.login.widget.LoginButton(Open Class,Show Error Log)“。我该如何解决这个问题。我需要显示登录页面,我该怎么做?
这是我的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 :(得分:0)
这是像这个
的fb sdk示例的xml代码<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>