小编bqu*_*que的帖子

LocalContext.current 上没有默认上下文

使用 LocalContext.current 会导致应用程序崩溃,告诉我:

java.lang.IllegalStateException: No default context
        at androidx.glance.CompositionLocalsKt$LocalContext$1.invoke(CompositionLocals.kt:35)
        at androidx.glance.CompositionLocalsKt$LocalContext$1.invoke(CompositionLocals.kt:35)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at androidx.compose.runtime.LazyValueHolder.getCurrent(ValueHolders.kt:29)
        at androidx.compose.runtime.LazyValueHolder.getValue(ValueHolders.kt:31)
        at androidx.compose.runtime.ComposerImpl.resolveCompositionLocal(Composer.kt:1776)
        at androidx.compose.runtime.ComposerImpl.consume(Composer.kt:1746)
        at com.bqubique.quran_randomayah.view.VerseCardKt.ButtonTile(VerseCard.kt:282)
        at com.bqubique.quran_randomayah.view.ComposableSingletons$VerseCardKt$lambda-2$1.invoke(VerseCard.kt:79)
        at com.bqubique.quran_randomayah.view.ComposableSingletons$VerseCardKt$lambda-2$1.invoke(VerseCard.kt:79)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:116)
        at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
        at
...
Run Code Online (Sandbox Code Playgroud)

使用的版本:

compose_version = '1.0.5'

wear_compose_version = '1.0.0-alpha15'

我尝试过在任何类型的 @Composable 中调用 LocalContext.current,甚至在 setContent{...} 内的 MainActivity.kt 中调用 LocalContext.current

wear-os android-jetpack android-jetpack-compose glance

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