在Android中更改方向时应用崩溃,我在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)
我不知道为什么要面对这个问题。我在这里有很多问题,特别是在改变方向时遇到这个问题的一些问题。
我无法追踪我遇到此错误的位置。我知道在RunFormActivity.java中会发生这种情况,但我在这一行中有很多代码,所以我无法跟踪。
在这里,错误在方向改变期间没有使用相同的id,但已经计算出但无法跟踪它的位置。
答案 0 :(得分:2)
从您的错误日志行
引起:java.lang.IllegalArgumentException:错误的状态类,期望View State但是收到了类android.widget.CompoundButton $ SavedState。当两个不同类型的视图在同一层次结构中具有相同的id时,通常会发生这种情况。该视图的id为id / 0x0。确保其他视图不使用相同的ID。
它表明您对两个以上不允许的视图使用相同的视图。您不能使用相同的视图ID来引用多个视图。在R.java
文件中注册您的观点时,它会发生冲突。
因此,请务必在布局文件中更改它并清理项目。
答案 1 :(得分:1)
当您提供相同的ID时,会导致此类异常。查看视图的ID,并确保其他人不使用相同的ID。