Compose java.lang.IlLegalStateException:尚未应用挂起的合成 [英] Compose java.lang.IllegalStateException: pending composition has not been applied

查看:16
本文介绍了Compose java.lang.IlLegalStateException:尚未应用挂起的合成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想运行简单的测试

class Exa {
@get:Rule
val composeTestRule = createAndroidComposeRule<MainActivity>()
// createComposeRule() if you don't need access to the activityTestRule

@Test
fun MyTest() {
    // Start the app
    composeTestRule.setContent {
            Greeting2("Nurs")
    }
    
    composeTestRule.onNodeWithText("Hello Nurs!").assertIsDisplayed()
}
}

@Composable
fun Greeting2(name: String) {
 Text(text = "Hello $name!")
}

但出现以下错误:

java.lang.IllegalStateException: pending composition has not been applied

奇怪的是,如果我在另一个项目中运行它,它会起作用

推荐答案

希望为来自谷歌的任何人添加一些细节。标题中列出的例外情况:

java.lang.IllegalStateException: pending composition has not been applied
如果Composable在合成或重新合成视图时引发异常,则抛出

。在原始发帖者注意到的情况下,很可能引发了异常,因为活动本身无法承载组合,但如果在可组合方法中引发异常,则其他代码可能会导致这种情况。

这篇关于Compose java.lang.IlLegalStateException:尚未应用挂起的合成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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