Compose preview shows a render problem in the issues panel
java.lang.NoSuchFieldError: view_tree_saved_state_registry_ownerShort answer
The preview runs your composable inside Android Studio, not on a device, so some libraries must be on the debug classpath and some code cannot run there. Read the exact exception in the issues panel: each one maps to a debugImplementation dependency, and a ViewModel failure means the screen needs a state-only composable.
Fix it fast
1Find out which cause you have
Open the preview's issues panel and copy the first exception line. The class or field name in it decides which cause applies.
# In Android Studio: open the Design tab of the file, click the red 'Render problem' link, read the first exception line2Match what you see, then jump to its fix
- 1
NoSuchFieldError: view_tree_saved_state_registry_owner, or ClassNotFoundException: androidx.savedstate.R$idThe saved-state libraries are missing from the debug classpathFix - 2
NoSuchFieldError: view_tree_lifecycle_ownerThe lifecycle runtime library is missingFix - 3
NoClassDefFoundError for androidx.customview.poolingcontainer.PoolingContainer or PoolingContainerListenerThe pooling container library is missingFix - 4
Failed to instantiate a ViewModel in the problems paneThe previewed composable creates a ViewModelFix
- 1
What does the error look like?
java.lang.NoSuchFieldError: view_tree_saved_state_registry_ownerjava.lang.ClassNotFoundException: androidx.savedstate.R$idjava.lang.NoSuchFieldError: view_tree_lifecycle_ownerjava.lang.NoClassDefFoundError: Could not initialize class androidx.customview.poolingcontainer.PoolingContainerFailed to instantiate a ViewModel
Cause 1 of 4
The saved-state libraries are missing from the debug classpath
1Check
Check whether the module already has the lifecycle saved-state artifact.
grep -rn "lifecycle-viewmodel-savedstate" --include=*.gradle --include=*.kts --include=*.toml .2Fix
Add a debugImplementation dependency on androidx.lifecycle:lifecycle-viewmodel-savedstate to the module.
dependencies {
debugImplementation("androidx.lifecycle:lifecycle-viewmodel-savedstate:<version>")
}3Verify
Sync, then use Build and Refresh in the preview.
./gradlew :app:assembleDebugConfirmed by developer.android.com
Cause 2 of 4
The lifecycle runtime library is missing
1Check
Look for the lifecycle runtime artifact in the module's dependencies.
grep -rn "lifecycle-runtime" --include=*.gradle --include=*.kts --include=*.toml .2Fix
Add a debugImplementation dependency on androidx.lifecycle:lifecycle-runtime.
dependencies {
debugImplementation("androidx.lifecycle:lifecycle-runtime:<version>")
}3Verify
Sync and refresh the preview; the field error should be gone.
./gradlew :app:assembleDebugConfirmed by developer.android.com
Cause 3 of 4
The pooling container library is missing
1Check
Search the module for the customview-poolingcontainer artifact.
grep -rn "customview-poolingcontainer" --include=*.gradle --include=*.kts --include=*.toml .2Fix
Add a debugImplementation dependency on androidx.customview:customview-poolingcontainer.
dependencies {
debugImplementation("androidx.customview:customview-poolingcontainer:<version>")
}3Verify
Sync and refresh the preview.
./gradlew :app:assembleDebugConfirmed by developer.android.com
Cause 4 of 4
The previewed composable creates a ViewModel
1Check
Find the composable under @Preview and see whether it calls viewModel() or receives a Hilt ViewModel as a parameter.
grep -rn "viewModel()\|hiltViewModel()" app/src/main2Fix
Previews cannot build repositories or an injected dependency graph. Split the screen into one composable that gets the ViewModel and a second that takes plain state parameters, and preview the second one with sample data.
@Composable
fun AuthorScreen(viewModel: AuthorViewModel = viewModel()) {
AuthorScreen(name = viewModel.authorName)
}
@Composable
fun AuthorScreen(name: String) { /* UI only */ }
@Preview
@Composable
fun AuthorScreenPreview() { AuthorScreen(name = "Sample") }3Verify
The preview renders without the ViewModel.
# Refresh the preview in the Design tabConfirmed by developer.android.com
How do I stop it coming back?
- Keep screen UI in composables that take state and events as parameters; only the top wrapper touches a ViewModel.
- Remember previews have no network or file access, so use sample data.
- Use LocalInspectionMode to show placeholder content where a real data source cannot run in a preview.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Mobile apps
Android app crashes because the Apache HTTP classes are missing
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;
From Android 9 the Apache HTTP client is no longer on the default classpath, so code or a library that still uses org.apache.http fails at runtime.
2 causes, each with a fixMobile apps
AGP 9 marks the android block as deprecated or fails on BaseExtension
java.lang.ClassCastException: class com.android.build.gradle.internal.dsl.ApplicationExtensionImpl$AgpDecorated_Decorated cannot be cast to class com.android.build.gradle.BaseExtension
AGP 9.0 uses only the new public DSL interfaces.
3 causes, each with a fixMobile apps
The editor cannot find R, so every R.string and R.id turns red
Unresolved reference: R
R is a class that the build generates from your res folder, in the package named by the module's namespace.
4 causes, each with a fixMobile apps
Android Studio says it could not identify the launch activity when you press Run
Run > Edit Configurations > Launch Options is set to Nothing or to a class that no longer exists
Android Studio launches the activity marked with a MAIN action and a LAUNCHER category in the merged manifest.
3 causes, each with a fixMobile apps
Gradle cannot apply the Android application or library plugin
Failed to apply plugin 'com.android.internal.application'.
Gradle loaded the Android Gradle plugin but could not run it.
2 causes, each with a fixMobile apps
FirebaseInstanceIdService and FirebaseInstanceId.getToken() no longer work
Deprecation warning on FirebaseInstanceId.getInstance().getToken()
Move token handling into a class that extends FirebaseMessagingService and override onNewToken, which runs when a token is first created and whenever it changes.
2 causes, each with a fix