java.lang.ClassCastException:android.view.AbsSavedState$1无法转换为android.widget.ScrollView$SavedState

slmsl1lt  于 2023-05-12  发布在  Android
关注(0)|答案(2)|浏览(149)

我最近开始在我们的生产应用程序中遇到以下异常。
{“androidApiLevel”:“28”,“osBuild”:“PQ2A.190405.003”}
设备:Pixel 2 XL
你知道这是怎么回事吗?

java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.ScrollView$SavedState
    at android.widget.ScrollView.onRestoreInstanceState(ScrollView.java:1834)
    at android.view.View.dispatchRestoreInstanceState(View.java:18608)
    at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3821)
    at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3827)
    at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3827)
    at android.view.View.restoreHierarchyState(View.java:18586)
    at androidx.e.a.d.restoreViewState(Fragment.java:494)
    at androidx.e.a.j.a(FragmentManager.java:1486)
    at androidx.e.a.j.f(FragmentManager.java:1784)
    at androidx.e.a.j.a(FragmentManager.java:1852)
    at androidx.e.a.j.e(FragmentManager.java:3269)
    at androidx.e.a.j.q(FragmentManager.java:3229)
    at androidx.e.a.g.f(FragmentController.java:201)
    at androidx.e.a.e.onStart(FragmentActivity.java:620)
    at androidx.appcompat.app.d.onStart(AppCompatActivity.java:178)
    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1391)
    at android.app.Activity.performStart(Activity.java:7165)
    at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2975)
    at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
    at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6718)
    at java.lang.reflect.Method.invoke(Method.java:-2)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
kninwzqo

kninwzqo1#

可能会有这样的情况,即您对两个元素使用相同的ID名称。
用其他视图重新检查分配给该滚动视图的ID

kkbh8khc

kkbh8khc2#

我通过遍历滚动视图的子视图并以编程方式为它们分配id来解决这个问题:

child.setId(generateViewId());

您可以使用getChildCount()getChildAt()等来迭代它们。

相关问题