错误如下:
E/AndroidRuntime(4908): FATAL EXCEPTION: main E/AndroidRuntime(4908): java.lang.IllegalStateException: Failure saving state: active FragmentName{42c63418} has cleared index: -1 E/AndroidRuntime(4908): at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1695) E/AndroidRuntime(4908): at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:499) E/AndroidRuntime(4908): at com.actionbarsherlock.app.SherlockFragmentActivity.onSaveInstanceState(SherlockFragmentActivity.java:127) E/AndroidRuntime(4908): at android.app.Activity.performSaveInstanceState(Activity.java:1147) E/AndroidRuntime(4908): at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1216) E/AndroidRuntime(4908): at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3129) E/AndroidRuntime(4908): at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3188) E/AndroidRuntime(4908): at android.app.ActivityThread.access$900(ActivityThread.java:141) E/AndroidRuntime(4908): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261) E/AndroidRuntime(4908): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(4908): at android.os.Looper.loop(Looper.java:137) E/AndroidRuntime(4908): at android.app.ActivityThread.main(ActivityThread.java:5041) E/AndroidRuntime(4908): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime(4908): at java.lang.reflect.Method.invoke(Method.java:511) E/AndroidRuntime(4908): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) E/AndroidRuntime(4908): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) E/AndroidRuntime(4908): at dalvik.system.NativeStart.main(Native Method)fragment中添加:
@Override public void onCreate(Bundle savedInstanceState) { setRetainInstance(true); super.onCreate(savedInstanceState); }