gpt4 book ai didi

Android: View 层次结构中的重复 ID

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:06:20 27 4
gpt4 key购买 nike

我有一个问题,来自市场的报告 - 应用程序严重崩溃,告诉我:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com....android/com....android.activities....}: java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.widget.ProgressBar$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/0x2. Make sure other views do not use the same id.

所以我知道这通常意味着它所说的 - 我在某个地方有重复 ID 的 View 。这很好,但让我担心的是,我认为重复的 id View 来 self 集成的某些 ad 网络。我试图在包含每个广告的 View 上使用 try/catch 来控制崩溃,但未能捕获它。

所以我的下一个想法是,广告 View 在这方面仍然有一些作用,但崩溃发生在另一个(我自己的) View 上,它具有相同的 ID。问题是,我不知道那个 View 是什么以及在哪里搜索它。你有什么想法可以是 id 0x2 的 View 吗? (还有 0x3 - 也有很多关于该 ID 的报告)?您是否遇到过与广告网络相关的类似崩溃?

对此真的很沮丧。任何帮助表示赞赏!

谢谢,丹

PS 完整的堆栈跟踪:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.....android/com.....android.activities....}: java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.widget.ProgressBar$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/0x2. Make sure other views do not use the same id. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667) at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2836) at android.app.ActivityThread.access$1600(ActivityThread.java:117) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3691) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.widget.ProgressBar$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/0x2. Make sure other views do not use the same id. at android.view.View.onRestoreInstanceState(View.java:6355) at android.view.View.dispatchRestoreInstanceState(View.java:6331) at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1211) at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1215) at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1215) at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1215) at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1215) at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1215) at android.view.View.restoreHierarchyState(View.java:6310) at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1537) at android.app.Activity.onRestoreInstanceState(Activity.java:850) at android.app.Activity.performRestoreInstanceState(Activity.java:822) at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1096) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1629) ... 12 more

最佳答案

从一个 fragment 切换到另一个包含相同 progressBar id 的 fragment 时遇到了这个问题。将 ID 更改为不同的 ID,问题就解决了。

关于Android: View 层次结构中的重复 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10191427/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com