kotlin Errors

42 error patterns

kotlin3 fixes

Jetpack Compose vertical scroll with infinite constraints

Android.*Compose.*IllegalStateException.*Vertically scrollable.*was measured with.*infinite.*constraints

  • Don't nest vertically scrollable components (LazyColumn in Column with scroll)
  • Use height(IntrinsicSize.Min) or explicit height modifier
kotlin3 fixes

Android Hilt injection not performed

Android.*Hilt.*IllegalStateException.*has not been.*injected

  • Annotate Activity/Fragment with @AndroidEntryPoint
  • Ensure Application class has @HiltAndroidApp annotation
kotlin3 fixes

Android Room migration incomplete

Android.*Room.*IllegalStateException.*Migration.*didn't properly handle

  • Ensure migration SQL covers all schema changes between versions
  • Use autoMigrations in @Database annotation for simple changes
kotlin3 fixes

Android R8/ProGuard missing class after obfuscation

Android.*R8.*Warning.*Missing class.*referenced from

  • Add -keep rule in proguard-rules.pro for the missing class
  • Add -dontwarn for expected missing classes (e.g., optional dependencies)
kotlin3 fixes

Jetpack Compose CompositionLocal not provided

Android.*Compose.*java\.lang\.IllegalStateException.*CompositionLocal.*not.*present

  • Wrap composable tree with CompositionLocalProvider
  • Provide the CompositionLocal value above the composable that reads it
kotlin3 fixes

Android Hilt ViewModel missing @Inject constructor

Android.*Hilt.*Cannot create.*@HiltViewModel.*without.*@Inject

  • Add @Inject constructor() to the ViewModel class
  • Annotate ViewModel with @HiltViewModel
kotlin3 fixes

Android Room cursor window full (row too large)

Android.*Room.*Cursor.*window.*full.*row too large

  • Limit query result columns to only those needed
  • Store large BLOBs externally and keep references in Room
kotlin3 fixes

Android ProGuard can't find referenced constructor

Android.*ProGuard.*Warning.*can't find referenced method.*constructor

  • Add -keep class rule for the class with missing constructor
  • Use @Keep annotation on classes instantiated via reflection
kotlin3 fixes

Jetpack Compose LazyColumn duplicate key

Android.*Compose.*LazyColumn.*Key.*was already used

  • Ensure key parameter in items() produces unique values for each item
  • Use item.id or unique identifier as key, not index
kotlin3 fixes

Jetpack Compose unnecessary recomposition from unstable params

Android.*Compose.*recomposition.*skipped.*unstable.*parameter

  • Mark data classes as @Stable or @Immutable
  • Use remember{} to stabilize lambda parameters
kotlin3 fixes

Android Hilt missing binding for dependency

Android.*Hilt.*MissingBinding.*cannot be provided without an @Provides

  • Create @Module with @Provides function for the type
  • Or annotate the class with @Inject constructor for automatic binding
kotlin3 fixes

Android Room unsupported field type

Android.*Room.*error:.*Cannot figure out how to save this field into database

  • Add @TypeConverter for the unsupported type
  • Register TypeConverters in @Database(typeConverters = [...])
kotlin3 fixes

Android class not found after R8 minification

Android.*R8.*ClassNotFoundException.*after minification

  • Add -keep rule for classes used via reflection
  • Use @Keep annotation on the class
kotlin3 fixes

Jetpack Compose ClassCast in composable singletons

Android.*Compose.*ClassCastException.*ComposableSingletons

  • Clean and rebuild the project: ./gradlew clean assembleDebug
  • Check for Compose compiler version mismatch with Kotlin version
kotlin3 fixes

Android Hilt WorkManager Worker injection failure

Android.*Hilt.*InstantiationException.*WorkManager.*Worker.*Inject

  • Use @HiltWorker annotation on the Worker class
  • Add @AssistedInject constructor with @Assisted for context and workerParams
kotlin3 fixes

Android Room missing migration between versions

Android.*Room.*IllegalArgumentException.*Migration path.*NOT find migration

  • Add Migration(oldVersion, newVersion) to database builder
  • Use fallbackToDestructiveMigration() for development only
kotlin3 fixes

Android R8 method too large after optimization

Android.*ProGuard.*R8.*ClassFormatError.*Method.*too large

  • Split large methods into smaller ones
  • Disable specific R8 optimizations: -dontoptimize for problematic class
kotlin3 fixes

Jetpack Compose function called from non-composable context

Android.*Compose.*Error:.*@Composable.*invocations.*can only happen from.*@Composable

  • Annotate the calling function with @Composable
  • Move composable call inside a proper composable scope
kotlin3 fixes

Android Hilt EntryPoint usage error

Android.*Hilt.*EntryPoints.*cannot be used in.*@HiltAndroidApp

  • Use EntryPointAccessors.fromApplication(context, MyEntryPoint::class.java)
  • Ensure @EntryPoint interface is annotated with @InstallIn(SingletonComponent::class)
kotlin3 fixes

Android Room DAO method missing annotation

Android.*Room.*Dao.*abstract.*method.*not annotated with.*Query.*Insert.*Update.*Delete

  • Add @Query, @Insert, @Update, or @Delete annotation to DAO methods
  • Ensure method return type matches the annotation (Insert returns Long/void)
kotlin3 fixes

Android AbstractMethodError after R8 obfuscation

Android.*R8.*AbstractMethodError.*after obfuscation

  • Add -keep rules for interfaces implemented via generics
  • Use -keepclassmembers for overridden abstract methods
kotlin3 fixes

Jetpack Compose RecyclerView interop crash with LazyColumn

Android.*Compose.*SnapHelper.*crash.*RecyclerView.*LazyColumn.*interop

  • Use pure Compose LazyColumn instead of RecyclerView interop
  • If interop is needed, use AndroidView with proper lifecycle handling
kotlin3 fixes

Kotlin NullPointerException

kotlin\.KotlinNullPointerException|java\.lang\.NullPointerException.*Kotlin

  • Use safe call operator ?. instead of direct access
  • Add null check with let: value?.let { ... }
kotlin4 fixes

lateinit property accessed before initialization

lateinit property.*has not been initialized

  • Initialize the property before accessing it
  • Use ::property.isInitialized check before access
kotlin3 fixes

ClassCastException in Kotlin

java\.lang\.ClassCastException.*cannot be cast to

  • Use safe cast: value as? TargetType
  • Check type before cast: if (value is TargetType) { ... }
kotlin3 fixes

Activity not declared in AndroidManifest

Unable to find explicit activity class.*have you declared this activity in.*AndroidManifest

  • Add <activity android:name=".YourActivity"/> to AndroidManifest.xml
  • Verify the fully qualified class name matches the manifest entry
kotlin4 fixes

Gradle dependency resolution failed

Could not resolve.*com\.android|Failed to resolve.*gradle

  • Add google() and mavenCentral() to repositories block
  • Check the dependency coordinates for typos
kotlin3 fixes

Jetpack Compose infinite recomposition loop

Recomposition.*infinite|Too many recompositions

  • Move state changes out of the composable body into LaunchedEffect or event handlers
  • Use remember { } to prevent recreating objects on every recomposition
kotlin3 fixes

Accessing member before super constructor completes

Cannot access.*before supertype constructor has been called

  • Move the initialization to an init block after super constructor
  • Use lazy initialization for the property
kotlin3 fixes

UI update from wrong thread on Android

Only the original thread that created a view hierarchy can touch its views

  • Use runOnUiThread { } or view.post { } to update UI from background
  • Use withContext(Dispatchers.Main) in coroutines
kotlin3 fixes

ViewModel missing no-arg constructor

ViewModelProvider.*has no zero argument constructor

  • Create a ViewModelFactory to provide constructor arguments
  • Use Hilt @HiltViewModel + @Inject constructor for DI
kotlin3 fixes

Unresolved reference in Kotlin

Unresolved reference:.*

  • Import the missing class or function
  • Check that the dependency providing it is in build.gradle
kotlin3 fixes

Nullable type where non-null expected

Type mismatch.*Required:.*Found:.*\?

  • Use !! operator if you're certain it's non-null (risky)
  • Use safe call with let: value?.let { nonNull -> ... }
kotlin3 fixes

Suspend function called outside coroutine

Suspension functions can be called only within coroutine body

  • Launch a coroutine: lifecycleScope.launch { suspendFun() }
  • Use viewModelScope.launch in ViewModel
kotlin3 fixes

Fragment operation when not attached to Activity

java\.lang\.IllegalStateException.*Fragment.*not attached to

  • Check isAdded before accessing context or activity
  • Use viewLifecycleOwner.lifecycleScope for Fragment coroutines
kotlin3 fixes

Kotlin compiler type incompatibility

e: Incompatible types.*expected.*found

  • Add explicit type conversion: .toInt(), .toString(), etc.
  • Check generic type parameters for variance issues
kotlin4 fixes

Layout XML inflation error

Caused by:.*InflateException.*Binary XML

  • Check for missing custom view class in the XML layout
  • Verify all required attributes are present in the XML
kotlin4 fixes

KAPT annotation processing failed

Execution failed for task ':app:kaptDebug.*

  • Check error above for the actual annotation processor failure
  • Clean and rebuild: ./gradlew clean assembleDebug
kotlin3 fixes

Resource leak detected by StrictMode

StrictMode.*Leaked.*closable

  • Use .use { } block for Closeable resources (auto-closes)
  • Close cursors, streams, and connections in finally block
kotlin3 fixes

Invalid notification configuration

RemoteServiceException.*Bad notification

  • Ensure notification channel is created before posting (Android 8+)
  • Set a valid small icon with setSmallIcon()
kotlin4 fixes

Background service start not allowed (Android 12+)

BackgroundServiceStartNotAllowedException

  • Use setForeground() for WorkManager expedited work
  • Use ForegroundService with foregroundServiceType declared in manifest
kotlin4 fixes

OOM from bitmap allocation

java\.lang\.OutOfMemoryError.*Failed to allocate.*bitmap

  • Use image loading library (Coil/Glide) with automatic downsampling
  • Set inSampleSize in BitmapFactory.Options to load smaller images