我从指南https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/设置了全新的项目和测试代码 一切都很好,但是当我添加时我正在逼近将此代码添加到我自己的应用程序中。
Session.openActiveSession(this, true, new Session.StatusCallback() {
这条线导致强制关闭
代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.przegladaj_layout);
// next line is 79, and makes force close
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.ulubionetv);
welcome.setText("Hello " + user.getName() + "!");
}
}
});
}
}
});
/* rest of code */
/* after onCreate */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
AndroidManifest
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<meta-data android:value="@string/app_id" android:name="com.facebook.sdk.ApplicationId"/>
<activity android:label="@string/app_name" android:name="com.facebook.LoginActivity"></activity>
日志输出
07-27 18:10:33.897: E/Trace(15621): error opening trace file: Permission denied (13)
07-27 18:10:34.413: E/AndroidRuntime(15621): FATAL EXCEPTION: main
07-27 18:10:34.413: E/AndroidRuntime(15621): java.lang.NoClassDefFoundError: android.support.v4.content.LocalBroadcastManager
07-27 18:10:34.413: E/AndroidRuntime(15621): at com.facebook.Session.postActiveSessionAction(Session.java:1215)
07-27 18:10:34.413: E/AndroidRuntime(15621): at com.facebook.Session.setActiveSession(Session.java:765)
07-27 18:10:34.413: E/AndroidRuntime(15621): at com.facebook.Session.openActiveSession(Session.java:865)
07-27 18:10:34.413: E/AndroidRuntime(15621): at com.facebook.Session.openActiveSession(Session.java:805)
07-27 18:10:34.413: E/AndroidRuntime(15621): at pl.evelan.law.murphy.ActPrzegladaj.onCreate(ActPrzegladaj.java:79)
07-27 18:10:34.413: E/AndroidRuntime(15621): at android.app.Activity.performCreate(Activity.java:5058)
07-27 18:10:34.413: E/AndroidRuntime(15621): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
07-27 18:10:34.413: E/AndroidRuntime(15621): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2104)
07-27 18:10:34.413: E/AndroidRuntime(15621): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2178)
07-27 18:10:34.413: E/AndroidRuntime(15621): at android.app.ActivityThread.access$700(ActivityThread.java:141)
07-27 18:10:34.413: E/AndroidRuntime(15621): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1271)
07-27 18:10:34.413: E/AndroidRuntime(15621): at android.os.Handler.dispatchMessage(Handler.java:99)
07-27 18:10:34.413: E/AndroidRuntime(15621): at android.os.Looper.loop(Looper.java:137)
07-27 18:10:34.413: E/AndroidRuntime(15621): at android.app.ActivityThread.main(ActivityThread.java:5118)
07-27 18:10:34.413: E/AndroidRuntime(15621): at java.lang.reflect.Method.invokeNative(Native Method)
07-27 18:10:34.413: E/AndroidRuntime(15621): at java.lang.reflect.Method.invoke(Method.java:511)
07-27 18:10:34.413: E/AndroidRuntime(15621): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
07-27 18:10:34.413: E/AndroidRuntime(15621): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
07-27 18:10:34.413: E/AndroidRuntime(15621): at dalvik.system.NativeStart.main(Native Method)