Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No default context on LocalContext.current

Using LocalContext.current results in app crash telling me:

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
...

Versions used:

compose_version = '1.0.5'

wear_compose_version = '1.0.0-alpha15'

I have tried calling LocalContext.current in any kind of @Composable, even in MainActivity.kt inside setContent{...}

like image 278
bqubique Avatar asked Mar 02 '26 12:03

bqubique


1 Answers

I guess the imports failed me. I was importing:

import androidx.glance.LocalContext

Instead of :

import androidx.compose.ui.platform.LocalContext
like image 157
bqubique Avatar answered Mar 05 '26 19:03

bqubique



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!