java.lang.IllegalStateException:在已放置的节点上调用 Place

问题描述 投票:0回答:3

尝试使用

 导航回来时出现 
java.lang.IllegalStateException: Place was called on a node which was placed already

错误
navController.navigateUp()

从某个特定屏幕,我找不到问题所在

我不知道我的导航可能出了什么问题,其他类似的屏幕工作正常

我发现了问题,在第一个屏幕上我有这个代码

LazyVerticalGrid(
            modifier = Modifier.padding(start = 0.dp, end = 0.dp),
            columns = GridCells.Fixed(2),
        ) {
            item(span = { GridItemSpan(maxLineSpan) }) {
                AssetTopItem(
                    modifier = Modifier
                        .padding(bottom = 20.dp, start = 15.dp, end = 15.dp),
                    item = uiState.asset
                )
            }
            item(span = { GridItemSpan(maxLineSpan) }) {
                ChartBlock(
                    chartState = uiState.chartState,
                    intervalsState = uiState.intervalState,
                    updateData = updateData,
                    changeInterval = changeInterval
                )
            }
            item(span = { GridItemSpan(maxLineSpan) }) {
                Column(
                    Modifier
                        .fillMaxWidth()
                        .background(
                            color = backgroundBlack,
                            shape = RoundedCornerShape(topStart = 10.dp, topEnd = 10.dp)
                        )
                ) {
                    CryptoTabs(modifier = Modifier, state = uiState.tabsState, setType = setTab)
                    OrdersBlock(state = uiState.offersState, scope = this@LazyVerticalGrid)
                }
            }
        }

我正在从这个屏幕导航到第二个屏幕,当我导航回来时,我发生了崩溃。但是当我的第一个屏幕上有这样的代码时

LazyVerticalGrid(
            modifier = Modifier.padding(start = 0.dp, end = 0.dp),
            columns = GridCells.Fixed(2),
        ) {
            item(span = { GridItemSpan(maxLineSpan) }) {
                AssetTopItem(
                    modifier = Modifier
                        .padding(bottom = 20.dp, start = 15.dp, end = 15.dp),
                    item = uiState.asset
                )
            }

            item(span = { GridItemSpan(maxLineSpan) }) {
                Column(
                    Modifier
                        .fillMaxWidth()
                        .background(
                            color = backgroundBlack,
                            shape = RoundedCornerShape(topStart = 10.dp, topEnd = 10.dp)
                        )
                ) {
                    CryptoTabs(modifier = Modifier, state = uiState.tabsState, setType = setTab)
                    OrdersBlock(state = uiState.offersState, scope = this@LazyVerticalGrid)
                }
            }
            item(span = { GridItemSpan(maxLineSpan) }) {
                ChartBlock(
                    chartState = uiState.chartState,
                    intervalsState = uiState.intervalState,
                    updateData = updateData,
                    changeInterval = changeInterval
                )
            }
        }

我没有崩溃:)wtf

android android-jetpack-compose
3个回答
0
投票

没有更多信息,我们只能猜测原因,但基于这个帖子和这个问题跟踪器。您的 compose 版本可能存在此问题。

根据问题跟踪器中的最新回复

androidx.compose.ui:ui:1.3.0

解决了这个问题。

您可能还想检查您的撰写版本,并从此处

检查其是否是最新的基础

0
投票

此异常的原因是对导航库的 alpha 版本的传递依赖


0
投票

我也面临着与我明确使用项目跨度相同的问题

像下面这样

item(span = { GridItemSpan(maxLineSpan) }) {
            ...
        }

后来我像上面一样删除了它,并使用了

span
参数,它带有
itemsIndexed()
扩展功能

itemsIndexed(
        items,
        span = { index, item -> (index % 3 == 0).select(GridItemSpan(maxLineSpan), GridItemSpan(1))}
    ) {}

并且它开始工作,没有崩溃

© www.soinside.com 2019 - 2024. All rights reserved.