I am trying to pass a test instance of one of my data classes into one of my composables in a preview and I’m getting
java.lang.NoClassDefFoundError: Could not initialize class...
whenever I try to create the data class instance within my preview composable function. Has anyone else run into this before?
Joseph Hawkes-Cates
11/17/2021, 9:51 PM
The code is essentially like this:
Copy code
@Preview("preview")
@Composable
fun Preview() {
val data = SomeDataClass(field1 = "value", field2 = "value")
MyScreenComposable(data = data)
}
This throws a NoClassDefFoundError within the Preview Error pane. It compiles fine through Gradle.
Joseph Hawkes-Cates
11/17/2021, 9:54 PM
The NoClassDefFoundError is saying it can’t find “SomeDataClass”
a
Abhinav Suthar
11/18/2021, 1:26 PM
I think clean build will fix this issue
j
Joseph Hawkes-Cates
11/18/2021, 4:51 PM
I tried that and still had the issue. I ended up just refactoring my composable so I could just pass primitives to it instead of the entire data class instance