小编mr.*_*uss的帖子

Compose BottomSheetScaffold IndexOutOfBoundsException 应用程序崩溃

我搜索了与此问题相关的解决方案,但一无所获。我解决了这个问题,所以我在这里发布问题和解决方案,目的是帮助某人。

问题描述

将 Jetpack Compose 从版本更新到 后1.2.0-beta021.2.0-rc02屏幕上的某些内容导致应用程序崩溃。

此特定屏幕上的代码在版本之间没有更改,因此崩溃必须是由我正在使用的 Compose 组件之一引起的。我设法通过反复试验的方法找到了崩溃的根源,并发现问题出在BottomSheetScaffold组件上(带有空,有点content)。

导致崩溃的代码:

BottomSheetScaffold(
        sheetContent = { Text(text = "Some sheet content") }
    ) {
        AlertDialog(
            onDismissRequest = {
                // no-op
            },
            buttons = {
                Text(text = "here goes a button")
            }
        )
    }
Run Code Online (Sandbox Code Playgroud)

崩溃日志:

2022-07-01 10:02:07.185 16257-16257/my.example.app E/AndroidRuntime: FATAL EXCEPTION: main
    Process: my.example.app, PID: 16257
    java.lang.IndexOutOfBoundsException: Index 0 is out of bounds. The list has 0 elements.
        at androidx.compose.runtime.collection.MutableVectorKt.checkIndex(MutableVector.kt:1135)
        at androidx.compose.runtime.collection.MutableVectorKt.access$checkIndex(MutableVector.kt:1)
        at androidx.compose.runtime.collection.MutableVector$MutableVectorList.get(MutableVector.kt:940) …
Run Code Online (Sandbox Code Playgroud)

android indexoutofboundsexception android-jetpack-compose android-bottomsheetdialog

5
推荐指数
1
解决办法
1749
查看次数