gpt4 book ai didi

android - 非法状态异常 : Could not convert SemanticsComponentNode to a View

转载 作者:行者123 更新时间:2023-11-29 23:10:44 26 4
gpt4 key购买 nike

我有一个非常简单的 @Composable 函数,我想在我的布局中使用它。但是,它最终会抛出一个 IllegalStateException,我无法弄清楚我在这里遗漏了什么。

class RallyActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Greeting("Tom")
}
}
}

@Composable
fun Greeting(name: String) {
Text(
"Hello, $name",
TextStyle(fontSize = 48.0F)
)
}
2019-05-09 06:32:33.214 5493-5493/androidx.ui.material.studies E/AndroidRuntime: FATAL EXCEPTION: main
Process: androidx.ui.material.studies, PID: 5493
java.lang.RuntimeException: Unable to start activity ComponentInfo{androidx.ui.material.studies/androidx.ui.material.studies.rally.RallyActivity}: java.lang.IllegalStateException: Could not convert SemanticsComponentNode to a View
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.IllegalStateException: Could not convert SemanticsComponentNode to a View
at androidx.compose.ViewApplyAdapter.end(ViewComposer.kt:104)
at androidx.compose.Applier.up(Applier.kt:53)
at androidx.compose.Composer$realizeSlots$10.invoke(Composer.kt:1049)
at androidx.compose.Composer$realizeSlots$10.invoke(Composer.kt:178)
at androidx.compose.Composer$applyChanges$1.invoke(Composer.kt:270)
at androidx.compose.Composer$applyChanges$1.invoke(Composer.kt:178)
at androidx.compose.SlotTable.write(SlotTable.kt:689)
at androidx.compose.Composer.applyChanges(Composer.kt:269)
at androidx.compose.CompositionContext$recompose$1.invoke(CompositionContext.kt:104)
at androidx.compose.CompositionContext$recompose$1.invoke(CompositionContext.kt:24)
at androidx.compose.CompositionContextKt.runWithCurrent(CompositionContext.kt:128)
at androidx.compose.CompositionContext.recompose(CompositionContext.kt:94)
at androidx.compose.Compose.composeInto(Compose.kt:135)
at androidx.compose.ComposeKt.compose(Compose.kt:265)
at androidx.compose.ComposeKt.setContent(Compose.kt:239)
at androidx.ui.material.studies.rally.RallyActivity.onCreate(RallyActivity.kt:46)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6494) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 

最佳答案

通过将 Greeting 可组合包装在 CraneWrapperRallyTheme 中解决了这个问题。

class RallyActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
CraneWrapper {
RallyTheme {
Greeting("Tom")
}
}
}
}
}

关于android - 非法状态异常 : Could not convert SemanticsComponentNode to a View,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56050892/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com