That kind of stack crawl looks like the view IDs of the fragment's view hierarchy being restored are not consistent with the hierarchy that was saved. That is, the previous view hierarchy saved the state for some view ID of a view that is not an AbsSpinner subclass as is the same ID here where it is being restored.
On Thu, May 12, 2011 at 9:59 AM, Karl Wagner <[email protected]> wrote: > Hi, > > I have a fragment that contains a linearlayout with a bunch of > controls to make an edit form (edittexts, spinners, buttons, etc). We > have a "review" button that replaces that fragment with a view form > (again a linearlayout, but with textviews only) and this transition > gets added to the back stack (so the user can change something if they > entered a wrong value). > > This is all hosted within the same activity. I create the first > fragment in code and call FragmentTransaction.replace() on the > container view. Both fragments dynamically create their content in > onCreateView(). This is also when the Spinner adapters get created. > > This all works fine, except that if I press the back button, the app > crashes (apparently trying to restore the instance state of a > spinner). I don't think I'm doing anything wrong (my code isn't even > in the stack trace, and this happens before onCreate). > > Logcat is below. > > Thanks, > > Karl > > > --------- beginning of /dev/log/system > --------- beginning of /dev/log/main > E/AndroidRuntime( 5510): FATAL EXCEPTION: main > E/AndroidRuntime( 5510): java.lang.ClassCastException: > android.view.AbsSavedStat > e$1 > E/AndroidRuntime( 5510): at > android.widget.AbsSpinner.onRestoreInstanceSt > ate(AbsSpinner.java:421) > E/AndroidRuntime( 5510): at > android.view.View.dispatchRestoreInstanceStat > e(View.java:6325) > E/AndroidRuntime( 5510): at > android.view.ViewGroup.dispatchThawSelfOnly(V > iewGroup.java:1292) > E/AndroidRuntime( 5510): at > android.widget.AdapterView.dispatchRestoreIns > tanceState(AdapterView.java:767) > E/AndroidRuntime( 5510): at > android.view.ViewGroup.dispatchRestoreInstanc > eState(ViewGroup.java:1279) > E/AndroidRuntime( 5510): at > android.view.ViewGroup.dispatchRestoreInstanc > eState(ViewGroup.java:1279) > E/AndroidRuntime( 5510): at > android.view.View.restoreHierarchyState(View. > java:6304) > E/AndroidRuntime( 5510): at > android.support.v4.app.Fragment.restoreViewSt > ate(Fragment.java:348) > E/AndroidRuntime( 5510): at > android.support.v4.app.FragmentManagerImpl.mo > veToState(FragmentManager.java:751) > E/AndroidRuntime( 5510): at > android.support.v4.app.FragmentManagerImpl.mo > veToState(FragmentManager.java:933) > E/AndroidRuntime( 5510): at > android.support.v4.app.BackStackRecord.popFro > mBackStack(BackStackRecord.java:639) > E/AndroidRuntime( 5510): at > android.support.v4.app.FragmentManagerImpl.po > pBackStackState(FragmentManager.java:1252) > E/AndroidRuntime( 5510): at > android.support.v4.app.FragmentManagerImpl.po > pBackStackImmediate(FragmentManager.java:407) > E/AndroidRuntime( 5510): at > android.support.v4.app.FragmentActivity.onBac > kPressed(FragmentActivity.java:150) > E/AndroidRuntime( 5510): at > android.app.Activity.onKeyDown(Activity.java: > 1861) > E/AndroidRuntime( 5510): at > android.support.v4.app.FragmentActivity.onKey > Down(FragmentActivity.java:322) > E/AndroidRuntime( 5510): at > android.view.KeyEvent.dispatch(KeyEvent.java: > 1494) > E/AndroidRuntime( 5510): at > android.app.Activity.dispatchKeyEvent(Activit > y.java:2123) > E/AndroidRuntime( 5510): at > com.android.internal.policy.impl.PhoneWindow$ > DecorView.dispatchKeyEvent(PhoneWindow.java:1715) > E/AndroidRuntime( 5510): at > android.view.ViewRoot.deliverKeyEventToViewHi > erarchy(ViewRoot.java:2664) > E/AndroidRuntime( 5510): at > android.view.ViewRoot.handleFinishedEvent(Vie > wRoot.java:2639) > E/AndroidRuntime( 5510): at > android.view.ViewRoot.handleMessage(ViewRoot. > java:1929) > E/AndroidRuntime( 5510): at > android.os.Handler.dispatchMessage(Handler.ja > va:99) > E/AndroidRuntime( 5510): at android.os.Looper.loop(Looper.java: > 143) > E/AndroidRuntime( 5510): at > android.app.ActivityThread.main(ActivityThrea > d.java:4196) > E/AndroidRuntime( 5510): at > java.lang.reflect.Method.invokeNative(Native > Method) > E/AndroidRuntime( 5510): at > java.lang.reflect.Method.invoke(Method.java:5 > 07) > E/AndroidRuntime( 5510): at com.android.internal.os.ZygoteInit > $MethodAndA > rgsCaller.run(ZygoteInit.java:839) > E/AndroidRuntime( 5510): at > com.android.internal.os.ZygoteInit.main(Zygot > eInit.java:597) > E/AndroidRuntime( 5510): at > dalvik.system.NativeStart.main(Native Method) > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Dianne Hackborn Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

