我已经使用这个教程制作了 FBLogin 演示
代码在这里 //MainActivity.java
package com.example.fbdemo;
import android.os.Bundle;
import android.app.Activity;
import com.facebook.*;
import com.facebook.model.*;
import android.widget.TextView;
import android.content.Intent;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// start Facebook Login
Session.openActiveSession(this, true, new Session.StatusCallback() {
// callback when session changes state
@Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
// make request to the /me API
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
TextView welcome = (TextView) findViewById(R.id.welcome);
welcome.setText("Hello " + user.getName() + "!");
}
}
});
}
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
}
//main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="TextView" />
</RelativeLayout>
//AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.fbdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.fbdemo.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.LoginActivity" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/app_id" />
</application>
</manifest>
错误就是这个。
02-14 16:40:43.245: E/AndroidRuntime(6300): FATAL EXCEPTION: main
02-14 16:40:43.245: E/AndroidRuntime(6300): java.lang.NoClassDefFoundError: com.example.fbdemo.MainActivity$1
02-14 16:40:43.245: E/AndroidRuntime(6300): at com.example.fbdemo.MainActivity.onCreate(MainActivity.java:18)
02-14 16:40:43.245: E/AndroidRuntime(6300): at android.app.Activity.performCreate(Activity.java:4465)
02-14 16:40:43.245: E/AndroidRuntime(6300): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
02-14 16:40:43.245: E/AndroidRuntime(6300): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
02-14 16:40:43.245: E/AndroidRuntime(6300): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
02-14 16:40:43.245: E/AndroidRuntime(6300): at android.app.ActivityThread.access$600(ActivityThread.java:123)
02-14 16:40:43.245: E/AndroidRuntime(6300): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
02-14 16:40:43.245: E/AndroidRuntime(6300): at android.os.Handler.dispatchMessage(Handler.java:99)
02-14 16:40:43.245: E/AndroidRuntime(6300): at android.os.Looper.loop(Looper.java:137)
02-14 16:40:43.245: E/AndroidRuntime(6300): at android.app.ActivityThread.main(ActivityThread.java:4424)
02-14 16:40:43.245: E/AndroidRuntime(6300): at java.lang.reflect.Method.invokeNative(Native Method)
02-14 16:40:43.245: E/AndroidRuntime(6300): at java.lang.reflect.Method.invoke(Method.java:511)
02-14 16:40:43.245: E/AndroidRuntime(6300): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
02-14 16:40:43.245: E/AndroidRuntime(6300): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
02-14 16:40:43.245: E/AndroidRuntime(6300): at dalvik.system.NativeStart.main(Native Method)
请给我解决方案。