但是,当应用程序启动并且应该创建 Facebook 会话时,应用程序崩溃了。我认为这些库没有包含在构建中......
package com.firstandroidapp;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.TextView;
import com.facebook.*;
import com.facebook.model.*;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_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);
}
}
这是异常堆栈:
10-16 14:13:30.627: E/AndroidRuntime(28793): FATAL EXCEPTION: main
10-16 14:13:30.627: E/AndroidRuntime(28793): java.lang.NoClassDefFoundError: android.support.v4.content.LocalBroadcastManager
10-16 14:13:30.627: E/AndroidRuntime(28793): at com.facebook.Session.postActiveSessionAction(Session.java:1327)
10-16 14:13:30.627: E/AndroidRuntime(28793): at com.facebook.Session.setActiveSession(Session.java:790)
10-16 14:13:30.627: E/AndroidRuntime(28793): at com.facebook.Session.openActiveSession(Session.java:890)
10-16 14:13:30.627: E/AndroidRuntime(28793): at com.facebook.Session.openActiveSession(Session.java:830)
10-16 14:13:30.627: E/AndroidRuntime(28793): at com.mumin.facebookconnect.FBAuth.onCreate(FBAuth.java:21)
10-16 14:13:30.627: E/AndroidRuntime(28793): at android.app.Activity.performCreate(Activity.java:5104)
10-16 14:13:30.627: E/AndroidRuntime(28793): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
10-16 14:13:30.627: E/AndroidRuntime(28793): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2260)
10-16 14:13:30.627: E/AndroidRuntime(28793): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2356)
10-16 14:13:30.627: E/AndroidRuntime(28793): at android.app.ActivityThread.access$600(ActivityThread.java:150)
10-16 14:13:30.627: E/AndroidRuntime(28793): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
10-16 14:13:30.627: E/AndroidRuntime(28793): at android.os.Handler.dispatchMessage(Handler.java:99)
10-16 14:13:30.627: E/AndroidRuntime(28793): at android.os.Looper.loop(Looper.java:137)
10-16 14:13:30.627: E/AndroidRuntime(28793): at android.app.ActivityThread.main(ActivityThread.java:5195)
10-16 14:13:30.627: E/AndroidRuntime(28793): at java.lang.reflect.Method.invokeNative(Native Method)
10-16 14:13:30.627: E/AndroidRuntime(28793): at java.lang.reflect.Method.invoke(Method.java:511)
10-16 14:13:30.627: E/AndroidRuntime(28793): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
10-16 14:13:30.627: E/AndroidRuntime(28793): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
10-16 14:13:30.627: E/AndroidRuntime(28793): at dalvik.system.NativeStart.main(Native Method)
10-16 14:13:38.175: I/Process(28793): Sending signal. PID: 28793 SIG: 9