Search code examples
androidandroid-studioandroid-jetpack-composeandroid-jetpack-compose-ui

Cannot skip the enclosing group while in an empty region


Currently I am developing UI components for native android application using Jetpack Compose and suddenly I seen an Exception while running the application in my device which crashes the application.

I am pasting the exception for the reference:

java.lang.IllegalArgumentException: Cannot skip the enclosing group while in an empty region
        at androidx.compose.runtime.SlotReader.skipToGroupEnd(SlotTable.kt:940)
        at androidx.compose.runtime.ComposerImpl.recomposeToGroupEnd(Composer.kt:2378)
        at androidx.compose.runtime.ComposerImpl.skipCurrentGroup(Composer.kt:2618)
        at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:3205)
        at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:3183)
        at androidx.compose.runtime.SnapshotStateKt__DerivedStateKt.observeDerivedStateRecalculations(DerivedState.kt:252)
        at androidx.compose.runtime.SnapshotStateKt.observeDerivedStateRecalculations(Unknown Source:1)
        at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:3183)
        at androidx.compose.runtime.ComposerImpl.recompose$runtime_release(Composer.kt:3148)
        at androidx.compose.runtime.CompositionImpl.recompose(Composition.kt:746)
        at androidx.compose.runtime.Recomposer.performRecompose(Recomposer.kt:876)
        at androidx.compose.runtime.Recomposer.access$performRecompose(Recomposer.kt:107)
        at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$2.invoke(Recomposer.kt:485)
        at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$2.invoke(Recomposer.kt:454)
        at androidx.compose.ui.platform.AndroidUiFrameClock$withFrameNanos$2$callback$1.doFrame(AndroidUiFrameClock.android.kt:34)
        at androidx.compose.ui.platform.AndroidUiDispatcher.performFrameDispatch(AndroidUiDispatcher.android.kt:109)
        at androidx.compose.ui.platform.AndroidUiDispatcher.access$performFrameDispatch(AndroidUiDispatcher.android.kt:41)
        at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.doFrame(AndroidUiDispatcher.android.kt:69)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1456)
        at android.view.Choreographer.doCallbacks(Choreographer.java:1256)
        at android.view.Choreographer.doFrame(Choreographer.java:946)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1443)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:264)
        at android.app.ActivityThread.main(ActivityThread.java:8315)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
        Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [androidx.compose.runtime.PausableMonotonicFrameClock@eb6b6ad, androidx.compose.ui.platform.MotionDurationScaleImpl@642ade2, StandaloneCoroutine{Cancelling}@a2b1573, AndroidUiDispatcher@ed35c30]

Solution

  • While looking for the solutions I found that this exception is causing due to return statement I have used in my composable. So, Don't use return statement in composable instead use if-else for branching composable or anything like that.