我完成了Android Facebook SDK 4 in Eclipse和https://developers.facebook.com/docs/android/getting-started#login_share
的所有步骤我的活动:
public class MainActivity extends Activity {
LoginButton loginButton;
CallbackManager callbackManager;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_main);
callbackManager = CallbackManager.Factory.create();
loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions("user_friends");
// Callback registration
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
}
@Override
public void onCancel() {
// App code
}
@Override
public void onError(FacebookException exception) {
// App code
}
});
final Button but_nova_hra = (Button) findViewById(R.id.nova_hra);
but_nova_hra.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent obrazovkaHry = new Intent(getApplicationContext(), HraActivity.class);
startActivity(obrazovkaHry);
}
});
final Button but_koniec = (Button) findViewById(R.id.konec);
but_koniec.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
}
});
}
}
应用程序在启动时崩溃
找不到从方法com.facebook.internal.Validate.hasFacebookActivity
引用的com.facebook.FacebookActivity
问题出在哪里?
编辑:刚刚创建了新的空白应用程序,完全相同的设置和FacebookSdk.sdkInitializing成功通过。这个特定的应用程序必须有一些问题,但在哪里?它们都有相同的设置吗?
答案 0 :(得分:0)
我想您需要在清单文件中声明FacebookActivity
,如此
<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" />
答案 1 :(得分:0)
LoL,我刚刚解决了我的问题。在活动布局中需要
工具:上下文=&#34; com.kajmus.appname.MainActivity&#34;