3

Facebook を自分のアプリに統合しようとしています。Facebook からダウンロードした Facebook のサンプル アプリを参照として使用ています (また、developer.facebookappIdでこのすべてのプロセスを生成しました)。簡単に言えば、アプリにライブラリ プロジェクトを追加し、Example.java を除く Facebook サンプル アプリのすべてのクラスをアプリにコピーするだけです。com_android_facebook

ここで、MyActivity クラスを Example.java クラスのように変更します。これは、MyActivity に Example クラスのすべてのコードとメインのアクティビティが含まれるようになったことを意味します。

そして、アプリのレイアウトを次のように変更します

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

今、アプリを実行すると、エラーが発生します

   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

どんな助け、提案も大歓迎です...

4

5 に答える 5

4

Facebook SDK のバージョン 3.0 以降、LoginButton は SDK の一部として com.facebook.widget.LoginButton として利用できるようになりました。

https://developers.facebook.com/docs/reference/android/3.0/LoginButtonを参照してください

ここでの Facebook 独自のアップグレード手順は、間違ったパッケージを参照していることに注意してください。LoginButton は、com.facebook.LoginButton ではなく、com.facebook.widget.LoginButton として宣言する必要があります。

于 2013-01-15T09:03:09.207 に答える
4

私も同じ問題に直面しました。main.xml を次のように変更しました。

<com.facebook.android.LoginButton
    android:id="@+id/login"
    android:src="@drawable/login_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:layout_margin="30dp"
    />

に (現在のパッケージは com.facebook.fbtest_simple です):

<com.facebook.fbtest_simple.LoginButton 
    android:id="@+id/login"
    android:src="@drawable/login_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:layout_margin="30dp"
    />

LoginButton は FB 標準ライブラリの一部ではないためです。

于 2012-02-26T11:17:11.017 に答える
2

LoginButtonそのSDKのメインソースにはありません。
サンプル コードでのみ使用できるため、使用できないクラスの読み込みに失敗するだけです ( ClassNotFoundException)...

于 2011-10-13T20:26:39.150 に答える
0

Initializing the Facebook SDK is what worked for me.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(this.getApplicationContext());
    setContentView(R.layout.activity_login);
}
于 2016-04-26T18:41:48.073 に答える
0

簡単なもの:

   10-14 00:58:37.786: ERROR/AndroidRuntime(3971): Caused by: java.lang.ClassNotFoundException: com.android.facebook.LoginButton in loader dalvik.system.PathClassLoader@44c06850

Facebook の src を検索すると、次のパスに移動できます。

AsyncFacebookRunner.java 、Facebook.java、FacebookError.java 、FbDialog.java、Util.java

..LoginButton のようなものがないことを確認すると、古いチュートリアルなどを使用していると考えることができます。

于 2011-10-13T20:26:43.357 に答える