Search code examples
androidandroid-orientation

App Crash when change orientation in android


App Crash when change orientation in android, I have following error in log cat:

 04-08 11:20:34.389: E/AndroidRuntime(926): FATAL EXCEPTION: main
    04-08 11:20:34.389: E/AndroidRuntime(926): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.project.dc.activity/com.project.dc.activity.RunFormActivity}: java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.widget.CompoundButton$SavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/0x0. Make sure other views do not use the same id.
    04-08 11:20:34.389: E/AndroidRuntime(926):  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3512)
    04-08 11:20:34.389: E/AndroidRuntime(926):  at android.app.ActivityThread.access$700(ActivityThread.java:130)
    04-08 11:20:34.389: E/AndroidRuntime(926):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1201)
    04-08 11:20:34.389: E/AndroidRuntime(926):  at android.os.Handler.dispatchMessage(Handler.java:99)
    04-08 11:20:34.389: E/AndroidRuntime(926):  at android.os.Looper.loop(Looper.java:137)
     04-08 11:20:34.389: E/AndroidRuntime(926):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
    04-08 11:20:34.389: E/AndroidRuntime(926):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    04-08 11:20:34.389: E/AndroidRuntime(926):  at dalvik.system.NativeStart.main(Native Method)
    04-08 11:20:34.389: E/AndroidRuntime(926): Caused by: java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.widget.CompoundButton$SavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/0x0. Make sure other views do not use the same id.

   04-08 11:20:34.389: E/AndroidRuntime(926):   at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1608)
    04-08 11:20:34.389: E/AndroidRuntime(926):  at android.app.Activity.onRestoreInstanceState(Activity.java:928)
    04-08 11:20:34.389: E/AndroidRuntime(926):  at android.app.Activity.performRestoreInstanceState(Activity.java:900)
    04-08 11:20:34.389: E/AndroidRuntime(926):  at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1130)
    04-08 11:20:34.389: E/AndroidRuntime(926):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2037)

I don't under stand why this is faced. I have many question here, particular some question i faced this problem during change orientation.

I could not track where i faced this error. I know in RunFormActivity.java this occurs, but i have many code in this line so i could not track.

Here, in error same id not used during orientation change, figured out but could not track where it is.


Solution

  • From your error log line

    Caused by: java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.widget.CompoundButton$SavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/0x0. Make sure other views do not use the same id.

    It shows that you are using the same view for more than two views which not allowed. You can not use the same view id to refer more than one view. Its conflicting while registering your views in R.java file.

    So make sure to change it in your layout file and clean your project.