Wrong state class, expecting View State but received class android.os.Bundle instead.

Caused by: java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.os.Bundle instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/layoutBase. Make sure other views do not use the same id.
        at android.view.View.onRestoreInstanceState(View.java:17663)
        at android.view.View.dispatchRestoreInstanceState(View.java:17638)
        at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3723)
        at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3729)
        at android.view.View.restoreHierarchyState(View.java:17616)
        at android.support.v4.app.Fragment.restoreViewState(Fragment.java:415)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1454)
        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1759)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1827)
        at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3244)
        at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3200)
        at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:2361)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1451)
        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1759)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1827)
        at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3244)
        at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3200)
        at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:195)
        at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:597)
        at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:177)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1333)
        at android.app.Activity.performStart(Activity.java:6992)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2780)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
        at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4754) 
        at android.app.ActivityThread.-wrap18(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1599) 
        at android.os.Handler.dispatchMessage(Handler.java:105) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6541) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

出现这种错误找不到原因,是因为引入自定义View中实现了onSaveInstanceState,并且返回的是自定义的类型,比如Bundle,而且布局中使用了相同的ID(一般UI都是有基类,具体实现类里面可能使用了一样的ID)

 

解决办法就是去掉相同的ID

你可能感兴趣的:(Android,笔记)