Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"render Issues" with Jetpack Compose

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

enter image description here

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")
    }
}
like image 405
sadat Avatar asked Jul 28 '26 09:07

sadat


2 Answers

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.

enter image description here

Then I pressed Render issues, View problems.

enter image description here

Or yellow exclamation mark:

enter image description here

Then pressed Render problems and found an error.

enter image description here

like image 179
CoolMind Avatar answered Jul 31 '26 03:07

CoolMind


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 { ... }
like image 25
Sergey Tosunyan Avatar answered Jul 31 '26 04:07

Sergey Tosunyan