このエラーが発生しています。他の質問を丸一日検索した後、あきらめて意見を聞くことにしました。これが私のコードです。実際には、Facebook認証チュートリアルページに記載されているコードです:
アクティビティ_メイン:
<?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.example.logindene.SplashFragment"
android:id="@+id/splashFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment android:name="com.example.logindene.SelectinFragment"
android:id="@+id/selectionFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
SplashFragment.java :
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.logindene.R;
public class SplashFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.splash,
container, false);
return view;
}
}
Splash.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#303040" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textColor="#AFDEFE"
android:textSize="28sp"
android:typeface="serif"
android:textStyle="italic"
android:text="@string/app_name" />
</LinearLayout>
<com.facebook.widget.LoginButton
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp" />
</LinearLayout>
そして最後に、 MainActivity.java :
package com.example.logindene;
import android.content.Intent;
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 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 SELECTION = 1;
private static final int FRAGMENT_COUNT = SELECTION +1;
private boolean isResumed = false;
private Fragment[] fragments = new Fragment[FRAGMENT_COUNT];
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 void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
uiHelper = new UiLifecycleHelper(this, callback);
uiHelper.onCreate(savedInstanceState);
FragmentManager fm = getSupportFragmentManager();
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();
}
@Override
public void onResume() {
super.onResume();
uiHelper.onResume();
isResumed = true;
}
@Override
public void onPause() {
super.onPause();
uiHelper.onPause();
isResumed = false;
}
@Override
public void onDestroy() {
super.onDestroy();
uiHelper.onDestroy();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
uiHelper.onSaveInstanceState(outState);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
uiHelper.onActivityResult(requestCode, resultCode, data);
}
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();
}
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);
}
}
}
selectionFragment のコードはまったく同じであるため、指定していません。また、activity_main.xml でフラグメント タグの場所を変更しても、同じエラーが再び発生します。
なぜそれが起こっているのでしょうか?
前もって感謝します。
編集:エラーメッセージを追加するのを忘れました。ここに行きます:
05-20 19:19:56.697: D/AndroidRuntime(1138): Shutting down VM
05-20 19:19:56.697: W/dalvikvm(1138): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
05-20 19:19:56.727: E/AndroidRuntime(1138): FATAL EXCEPTION: main
05-20 19:19:56.727: E/AndroidRuntime(1138): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.logindene/com.example.logindene.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.os.Handler.dispatchMessage(Handler.java:99)
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.os.Looper.loop(Looper.java:137)
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-20 19:19:56.727: E/AndroidRuntime(1138): at java.lang.reflect.Method.invokeNative(Native Method)
05-20 19:19:56.727: E/AndroidRuntime(1138): at java.lang.reflect.Method.invoke(Method.java:511)
05-20 19:19:56.727: E/AndroidRuntime(1138): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-20 19:19:56.727: E/AndroidRuntime(1138): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-20 19:19:56.727: E/AndroidRuntime(1138): at dalvik.system.NativeStart.main(Native Method)
05-20 19:19:56.727: E/AndroidRuntime(1138): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-20 19:19:56.727: E/AndroidRuntime(1138): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.app.Activity.setContentView(Activity.java:1881)
05-20 19:19:56.727: E/AndroidRuntime(1138): at com.example.logindene.MainActivity.onCreate(MainActivity.java:38)
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.app.Activity.performCreate(Activity.java:5104)
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-20 19:19:56.727: E/AndroidRuntime(1138): ... 11 more
05-20 19:19:56.727: E/AndroidRuntime(1138): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.example.logindene.SplashFragment: make sure class name exists, is public, and has an empty constructor that is public
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
05-20 19:19:56.727: E/AndroidRuntime(1138): ... 21 more
05-20 19:19:56.727: E/AndroidRuntime(1138): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.logindene.SplashFragment" on path: /data/app/com.example.logindene-2.apk
05-20 19:19:56.727: E/AndroidRuntime(1138): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
05-20 19:19:56.727: E/AndroidRuntime(1138): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-20 19:19:56.727: E/AndroidRuntime(1138): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-20 19:19:56.727: E/AndroidRuntime(1138): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
05-20 19:19:56.727: E/AndroidRuntime(1138): ... 24 more
05-20 19:22:42.217: E/Trace(1183): error opening trace file: No such file or directory (2)
05-20 19:22:43.267: D/AndroidRuntime(1183): Shutting down VM
05-20 19:22:43.267: W/dalvikvm(1183): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
05-20 19:22:43.297: E/AndroidRuntime(1183): FATAL EXCEPTION: main
05-20 19:22:43.297: E/AndroidRuntime(1183): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.logindene/com.example.logindene.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.os.Handler.dispatchMessage(Handler.java:99)
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.os.Looper.loop(Looper.java:137)
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-20 19:22:43.297: E/AndroidRuntime(1183): at java.lang.reflect.Method.invokeNative(Native Method)
05-20 19:22:43.297: E/AndroidRuntime(1183): at java.lang.reflect.Method.invoke(Method.java:511)
05-20 19:22:43.297: E/AndroidRuntime(1183): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-20 19:22:43.297: E/AndroidRuntime(1183): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-20 19:22:43.297: E/AndroidRuntime(1183): at dalvik.system.NativeStart.main(Native Method)
05-20 19:22:43.297: E/AndroidRuntime(1183): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-20 19:22:43.297: E/AndroidRuntime(1183): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.app.Activity.setContentView(Activity.java:1881)
05-20 19:22:43.297: E/AndroidRuntime(1183): at com.example.logindene.MainActivity.onCreate(MainActivity.java:38)
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.app.Activity.performCreate(Activity.java:5104)
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-20 19:22:43.297: E/AndroidRuntime(1183): ... 11 more
05-20 19:22:43.297: E/AndroidRuntime(1183): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.example.logindene.SplashFragment: make sure class name exists, is public, and has an empty constructor that is public
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
05-20 19:22:43.297: E/AndroidRuntime(1183): ... 21 more
05-20 19:22:43.297: E/AndroidRuntime(1183): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.logindene.SplashFragment" on path: /data/app/com.example.logindene-1.apk
05-20 19:22:43.297: E/AndroidRuntime(1183): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
05-20 19:22:43.297: E/AndroidRuntime(1183): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-20 19:22:43.297: E/AndroidRuntime(1183): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-20 19:22:43.297: E/AndroidRuntime(1183): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
05-20 19:22:43.297: E/AndroidRuntime(1183): ... 24 more
05-20 19:27:43.357: I/Process(1183): Sending signal. PID: 1183 SIG: 9