I am having some render issue while showing the jetpack components. The screenshot is like this

If I click on the error icon from the screenshot, it shows
java.lang.ClassNotFoundException: androidx.activity.compose.LocalOnBackPressedDispatcherOwner
at java.lang.ClassLoader.loadClass(ClassLoader.java:589)
at java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at androidx.compose.ui.tooling.ComposeViewAdapter.WrapPreview ... (ComposeViewAdapter.kt:528)
at androidx.compose.ui.tooling.ComposeViewAdapter.access$WrapPreview(ComposeViewAdapter.kt:124)
at androidx.compose.ui.tooling.ComposeViewAdapter$init$3.invoke(ComposeViewAdapter.kt:583)
at androidx.compose.ui.tooling.ComposeViewAdapter$init$3.invoke(ComposeViewAdapter.kt:580)
The composable is something like
@Composable
@Preview
fun TestCompose(){
Column {
Text(text = "something")
}
}
In my case first I solved by pressing the button Sync Project with Gradle Files or Build & Refresh (green arrows in a right top corner). But later it didn't help.

Then I pressed Render issues, View problems.

Or yellow exclamation mark:

Then pressed Render problems and found an error.

In my case, the issue was caused by using a singleton object for a custom IndicationInstance implementation. The preview was failing with a "java.lang.IllegalStateException: Cannot delegate to an already delegated node" error.
The solution was to simply change the NoIndicationInstance from an object (singleton) to a class. This ensures that a new instance is created each time it's used, preventing conflicts in delegation across multiple previews.
// Change this
object NoIndicationInstance : Modifier.Node(), DrawModifierNode { ... }
// To this
class NoIndicationInstance : Modifier.Node(), DrawModifierNode { ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With