画面をオフにしてから再びオンにすると、アプリケーションが閉じます。
Logcat は、このエラーの原因が Fragment を拡張する CourseFragment.class の Java 行 60 を指していることを示しています。
mViewPager.setAdapter(infoTechPageAdapter);
Fragment を拡張する CourseFragment.class に ViewPager を実装しています。
これが私のコードです:
public class CourseFragment extends Fragment {
public static final String ARG_POSITION_NUMBER = "course_number";
private int position;
public CourseFragment() {
// Empty constructor required for fragment subclasses
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView;
position = getArguments().getInt("position");
String course = getResources().getStringArray(
R.array.array_navigation_drawer)[position];
getActivity().setTitle(course);
rootView = inflater.inflate(R.layout.activity_drawer_fragment,
container, false);
return rootView;
}// end onCreateView
@Override
public void onStart() {
super.onStart();
ViewPager mViewPager = (ViewPager) getActivity().findViewById(
R.id.pagerYear);
Log.i("posit", String.valueOf(position));
switch (position) {
case 0:
InfoTechPageAdapter infoTechPageAdapter = new InfoTechPageAdapter(
getActivity().getSupportFragmentManager());
mViewPager.setAdapter(infoTechPageAdapter);
break;
case 1:
ComSciPageAdapter comSciPageAdapter = new ComSciPageAdapter(
getActivity().getSupportFragmentManager());
mViewPager.setAdapter(comSciPageAdapter);
break;
case 2:
ProfilePageAdapter profilePageAdapter = new ProfilePageAdapter(
getActivity().getSupportFragmentManager());
mViewPager.setAdapter(profilePageAdapter);
break;
}
}// end onStart
}
ログキャット
09-22 10:54:03.830: E/AndroidRuntime(2917): FATAL EXCEPTION: main
09-22 10:54:03.830: E/AndroidRuntime(2917): java.lang.IllegalStateException: Observer android.support.v4.view.ViewPager$PagerObserver@4239b3e8 was not registered.
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.database.Observable.unregisterObserver(Observable.java:69)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.support.v4.view.PagerAdapter.unregisterDataSetObserver(PagerAdapter.java:294)
09-22 10:54:03.830: E/AndroidRuntime(2917): at com.usjr.sss.adapter.InfoTechPageAdapter.unregisterDataSetObserver(InfoTechPageAdapter.java:21)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.support.v4.view.ViewPager.setAdapter(ViewPager.java:409)
09-22 10:54:03.830: E/AndroidRuntime(2917): at com.usjr.sss.fragment.CourseFragment.onStart(CourseFragment.java:60)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.support.v4.app.Fragment.performStart(Fragment.java:1502)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:957)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:472)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.support.v4.view.ViewPager.setAdapter(ViewPager.java:415)
09-22 10:54:03.830: E/AndroidRuntime(2917): at com.usjr.sss.fragment.CourseFragment.onStart(CourseFragment.java:60)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.support.v4.app.Fragment.performStart(Fragment.java:1502)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:957)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.support.v4.app.FragmentManagerImpl.dispatchStart(FragmentManager.java:1882)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:573)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1164)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.app.Activity.performStart(Activity.java:5114)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.app.Activity.performRestart(Activity.java:5169)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.app.ActivityThread.handleSleeping(ActivityThread.java:3408)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.app.ActivityThread.access$2700(ActivityThread.java:153)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1426)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.os.Handler.dispatchMessage(Handler.java:99)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.os.Looper.loop(Looper.java:137)
09-22 10:54:03.830: E/AndroidRuntime(2917): at android.app.ActivityThread.main(ActivityThread.java:5227)
09-22 10:54:03.830: E/AndroidRuntime(2917): at java.lang.reflect.Method.invokeNative(Native Method)
09-22 10:54:03.830: E/AndroidRuntime(2917): at java.lang.reflect.Method.invoke(Method.java:511)
09-22 10:54:03.830: E/AndroidRuntime(2917): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
09-22 10:54:03.830: E/AndroidRuntime(2917): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
09-22 10:54:03.830: E/AndroidRuntime(2917): at dalvik.system.NativeStart.main(Native Method)