---
title: "How do you fix \"lateinit property has not been initialized\" in Kotlin?"
description: "The lateinit property was read before it was assigned. Initialize it earlier, check isInitialized, or use a nullable type, by lazy or a constructor value."
url: "https://bugsee.com/answers/android/fix-lateinit-property-not-initialized/"
---

# How do you fix "lateinit property has not been initialized" in Kotlin?

A `lateinit var` was read before anything assigned it. Make sure it is set before first use, or choose a safer pattern such as `by lazy`, a nullable type or constructor injection.

```kotlin
class ProfileFragment : Fragment() {
    private lateinit var adapter: ProfileAdapter

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        adapter = ProfileAdapter()           // assign before any read
    }

    fun refresh() {
        if (::adapter.isInitialized) adapter.notifyDataSetChanged()
    }
}

// Alternatives
private val adapter by lazy { ProfileAdapter() }   // created on first use
private var adapter: ProfileAdapter? = null        // explicit "not yet" state
```

- Lifecycle order is the usual cause: a callback runs before the method that assigns the property, or after the view was destroyed.
- Use `::property.isInitialized` only as a guard; if you need it often, the property probably should be nullable.
- Prefer `val` with `by lazy` or constructor parameters when the value never changes.

## Related questions

- [How do you fix NetworkOnMainThreadException in Android?](https://bugsee.com/answers/android/fix-network-on-main-thread-exception/)
- [How do you deobfuscate an Android stack trace?](https://bugsee.com/answers/android/deobfuscate-a-stack-trace/)
