jetpack撰写java.lang.IllegalStateException:开始/结束不平衡 [英] jetpack compose java.lang.IllegalStateException: Start/end imbalance

查看:63
本文介绍了jetpack撰写java.lang.IllegalStateException:开始/结束不平衡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这段代码会导致崩溃:

我使用撰写版本1.0.0-alpha06

im using compose version 1.0.0-alpha06

java.lang.IllegalStateException:在androidx.compose.runtime.Composer.finalizeCompose(Composer.kt:2369)处开始/结束不平衡,在androidx.compose.runtime.Composer.endRoot(Composer.kt:575)处发生.compose.runtime.Composer.composeInitial(Composer.kt:2054)在androidx.compose.runtime.Recomposer.composeInitial $ runtime_release(Recomposer.kt:276)在androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:110)在androidx.compose.ui.platform.WrappedComposition $ setContent $ 1.invoke(Wrapper.kt:234)在androidx.compose.ui.platform.WrappedComposition $ setContent $ 1.invoke(Wrapper.kt:-1)在androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.kt:627)在android.view.View.dispatchAttachedToWindow(View.java:20479)在android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3489)在android.view.ViewGroup在android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3496)的.dispatchAttachedToWindow(ViewGroup.java:3496)android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3496)在android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3496)在android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:44)

java.lang.IllegalStateException: Start/end imbalance   at androidx.compose.runtime.Composer.finalizeCompose(Composer.kt:2369)   at androidx.compose.runtime.Composer.endRoot(Composer.kt:575)   at androidx.compose.runtime.Composer.composeInitial(Composer.kt:2054)   at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(Recomposer.kt:276)   at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:110)   at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.kt:234)   at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.kt:-1)   at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.kt:627)   at android.view.View.dispatchAttachedToWindow(View.java:20479)   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3489)   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3496)   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3496)   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3496)   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3496)   at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:44)

有人可以帮助我吗?谢谢

can someone help me? thanks

@Composable
@Preview
private fun Image1() {
    Box(modifier = Modifier.fillMaxWidth().wrapContentHeight()) {
        Image(
                asset = imageResource(id = R.mipmap.fit_static_image_1),
                contentScale = ContentScale.FillWidth,
        )
        Column(Modifier.padding(start = 16.dp, end = 16.dp).align(Alignment.CenterStart), horizontalAlignment = Alignment.Start) {
            Text(
                    color = getColor(id = R.color.white),
                    fontWeight = FontWeight.Bold,
                    fontSize = TextUnit.Sp(18),
                    text = dicString(id = R.string.fit_static_image_1_title),
                    textAlign = TextAlign.Start
            )
            Text(
                    text = dicString(id = R.string.fit_static_image_1_description),
                    color = getColor(id = R.color.white),
                    fontSize = TextUnit.Sp(14),
                    modifier = Modifier.padding(top = 4.dp),
                    textAlign = TextAlign.Start
            )
        }
    }
}

推荐答案

我使用了记住{} 错误,我试图在 dicString 函数中使用它来记住获得的字符串.这引起了问题.我通过将资源ID添加到Remember函数作为参数来解决此问题.记住(id){}

i was using remember { } wrong, i was trying to use it in dicString function to remember obtained string. That caused the issue. I fixed that by adding the resource id to the remember function as parameter. remember( id ) { }

这篇关于jetpack撰写java.lang.IllegalStateException:开始/结束不平衡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆