All posts

Fix Missing Import in Kotlin

Resolve import errors in Kotlin projects covering Gradle dependency resolution, extension function imports, and Kotlin/Java interop.

Missing Import Errors in Kotlin

Kotlin's Unresolved reference error is the equivalent of Java's cannot find symbol. It means the compiler can't find the class, function, or property you're referencing.

Auto-Imported Standard Library

Kotlin auto-imports kotlin.*, kotlin.collections.*, etc. But extension functions from other packages need explicit imports:

// Error: Unresolved reference: joinToString
// This IS auto-imported, but if you see this error,
// check you're calling it on the right type

// Extension functions from kotlinx need explicit import
import kotlinx.coroutines.launch
import kotlinx.coroutines.delay

Gradle Dependencies

// build.gradle.kts
dependencies {
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
    implementation("io.ktor:ktor-server-core:2.3.7")
}

Kotlin/Java Interop

Java classes are imported normally, but Kotlin companion objects need special handling:

import java.time.LocalDateTime
import java.util.UUID

// Kotlin companion object from Java:
// MyClass.Companion.create() in Java
// MyClass.create() in Kotlin (automatic)

Extension Functions From Other Modules

// These look like methods but are actually imported functions
import com.example.utils.toSlug  // Extension on String

val slug = "My Title".toSlug()

Typealias Confusion

// If a typealias is in another file, it needs importing
// In types.kt:
typealias UserId = String

// In another file:
import com.example.types.UserId

Bugsly captures ClassNotFoundException in Kotlin JVM apps and Unresolved reference build errors via CI integration.

Try Bugsly Free

AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.

Get Started Free