初めて Facebook ログインでアプリを作成しようとしていますが、ガイドのすべての手順に従いました: https://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/アプリを試して実行すると、LogCat に次のエラーが表示されます。
07-15 20:32:49.081: D/ActivityThread(18598): setTargetHeapUtilization:0.25
07-15 20:32:49.091: D/ActivityThread(18598): setTargetHeapIdealFree:8388608
07-15 20:32:49.091: D/ActivityThread(18598): setTargetHeapConcurrentStart:2097152
07-15 20:32:49.551: D/AndroidRuntime(18598): Shutting down VM
07-15 20:32:49.551: W/dalvikvm(18598): threadid=1: thread exiting with uncaught exception (group=0x41b1c378)
07-15 20:32:49.641: E/AndroidRuntime(18598): FATAL EXCEPTION: main
07-15 20:32:49.641: E/AndroidRuntime(18598): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.alexlamond.fblogin/com.alexlamond.fblogin.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
07-15 20:32:49.641: E/AndroidRuntime(18598): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2071)
07-15 20:32:49.641: E/AndroidRuntime(18598): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
07-15 20:32:49.641: E/AndroidRuntime(18598): at android.app.ActivityThread.access$600(ActivityThread.java:138)
07-15 20:32:49.641: E/AndroidRuntime(18598): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
07-15 20:32:49.641: E/AndroidRuntime(18598): at android.os.Handler.dispatchMessage(Handler.java:99)
07-15 20:32:49.641: E/AndroidRuntime(18598): at android.os.Looper.loop(Looper.java:213)
07-15 20:32:49.641: E/AndroidRuntime(18598): at android.app.ActivityThread.main(ActivityThread.java:4787)
07-15 20:32:49.641: E/AndroidRuntime(18598): at java.lang.reflect.Method.invokeNative(Native Method)
07-15 20:32:49.641: E/AndroidRuntime(18598): at java.lang.reflect.Method.invoke(Method.java:511)
07-15 20:32:49.641: E/AndroidRuntime(18598): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
07-15 20:32:49.641: E/AndroidRuntime(18598): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
07-15 20:32:49.641: E/AndroidRuntime(18598): at dalvik.system.NativeStart.main(Native Method)
07-15 20:32:49.641: E/AndroidRuntime(18598): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
07-15 20:32:49.641: E/AndroidRuntime(18598): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
07-15 20:32:49.641: E/AndroidRuntime(18598): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
07-15 20:32:49.641: E/AndroidRuntime(18598): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-15 20:32:49.641: E/AndroidRuntime(18598): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-15 20:32:49.641: E/AndroidRuntime(18598): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-15 20:32:49.641: E/AndroidRuntime(18598): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:262)
07-15 20:32:49.641: E/AndroidRuntime(18598): at android.app.Activity.setContentView(Activity.java:1867)
07-15 20:32:49.641: E/AndroidRuntime(18598): at com.alexlamond.fblogin.MainActivity.onCreate(MainActivity.java:30)
07-15 20:32:49.641: E/AndroidRuntime(18598): at android.app.Activity.performCreate(Activity.java:5008)
07-15 20:32:49.641: E/AndroidRuntime(18598): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
07-15 20:32:49.641: E/AndroidRuntime(18598): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2035)
07-15 20:32:49.641: E/AndroidRuntime(18598): ... 11 more
07-15 20:32:49.641: E/AndroidRuntime(18598): Caused by: java.lang.ClassCastException: com.alexlamond.fblogin.SelectionFragment cannot be cast to android.support.v4.app.Fragment
07-15 20:32:49.641: E/AndroidRuntime(18598): at android.support.v4.app.Fragment.instantiate(Fragment.java:394)
07-15 20:32:49.641: E/AndroidRuntime(18598): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
07-15 20:32:49.641: E/AndroidRuntime(18598): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
07-15 20:32:49.641: E/AndroidRuntime(18598): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
07-15 20:32:49.641: E/AndroidRuntime(18598): ... 21 more
私がメイン アクティビティの Java ファイルと xml レイアウト ファイルに持っているコードは、Facebook が入力するように言ったものと同じです。
MainActivity.Java:
package com.alexlamond.fblogin;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;
import android.view.MenuItem;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.UiLifecycleHelper;
public class MainActivity extends FragmentActivity {
private static final int SPLASH = 0;
private static final int SETTINGS = 2;
private static final int SELECTION = 1;
private static final int FRAGMENT_COUNT = SETTINGS +1;
private MenuItem settings;
private boolean isResumed = false;;
private Fragment[] fragments = new Fragment[FRAGMENT_COUNT];
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
uiHelper = new UiLifecycleHelper(this, callback);
uiHelper.onCreate(savedInstanceState);
FragmentManager fm = getSupportFragmentManager();
fragments[SELECTION] = fm.findFragmentById(R.id.selectionFragment);
fragments[SETTINGS] = fm.findFragmentById(R.id.userSettingsFragment);
fragments[SPLASH] = fm.findFragmentById(R.id.splashFragment);
fragments[SELECTION] = fm.findFragmentById(R.id.selectionFragment);
FragmentTransaction transaction = fm.beginTransaction();
for(int i = 0; i < fragments.length; i++) {
transaction.hide(fragments[i]);
}
transaction.commit();
}
private void showFragment(int fragmentIndex, boolean addToBackStack) {
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction transaction = fm.beginTransaction();
for (int i = 0; i < fragments.length; i++) {
if (i == fragmentIndex) {
transaction.show(fragments[i]);
} else {
transaction.hide(fragments[i]);
}
}
if (addToBackStack) {
transaction.addToBackStack(null);
}
transaction.commit();
}
@Override
public void onResume() {
super.onResume();
isResumed = true;
}
@Override
public void onPause() {
super.onPause();
isResumed = false;
}
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
// Only make changes if the activity is visible
if (isResumed) {
FragmentManager manager = getSupportFragmentManager();
// Get the number of entries in the back stack
int backStackSize = manager.getBackStackEntryCount();
// Clear the back stack
for (int i = 0; i < backStackSize; i++) {
manager.popBackStack();
}
if (state.isOpened()) {
// If the session state is open:
// Show the authenticated fragment
showFragment(SELECTION, false);
} else if (state.isClosed()) {
// If the session state is closed:
// Show the login fragment
showFragment(SPLASH, false);
}
}
}
@Override
protected void onResumeFragments() {
super.onResumeFragments();
Session session = Session.getActiveSession();
if (session != null && session.isOpened()) {
// if the session is already open,
// try to show the selection fragment
showFragment(SELECTION, false);
} else {
// otherwise present the splash screen
// and ask the person to login.
showFragment(SPLASH, false);
}
}
private UiLifecycleHelper uiHelper;
private Session.StatusCallback callback =
new Session.StatusCallback() {
@Override
public void call(Session session,
SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
}
};
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// only add the menu when the selection fragment is showing
if (fragments[SELECTION].isVisible()) {
if (menu.size() == 0) {
settings = menu.add(R.string.settings);
}
return true;
} else {
menu.clear();
settings = null;
}
return false;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.equals(settings)) {
showFragment(SETTINGS, true);
return true;
}
return false;
}
}
と私の activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment android:name="com.alexlamond.fblogin.SelectionFragment"
android:id="@+id/selectionFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment android:name="com.alexlamond.fblogin.SplashFragment"
android:id="@+id/splashFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment android:name="com.alexlamond.fblogin.UserSettingsFragment"
android:id="@+id/userSettingsFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
エミュレーター経由で実行すると、コンソールに次の結果が表示されます。
[2013-07-15 20:51:04 - FacebookLogin] Starting activity com.alexlamond.fblogin.MainActivity on device emulator-5554
[2013-07-15 20:51:04 - FacebookLogin] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.alexlamond.fblogin/.MainActivity }
[2013-07-15 20:51:05 - FacebookLogin] ActivityManager: Warning: Activity not started, its current task has been brought to the front
これは何か関係があるのでしょうか?