UninitializedPropertyAccessException: lateinit property has not been initialized

f you're using Kotlin 1.2, you can easily check whether a lateinit variable has been initialized or not. If not, well, you can always use the not null approach.

Anyways, here's how you can check if a lateinit var has been initialized or not:

if (::fullName.isInitialized) {
    print("Hi, $fullName")
}

have a look at my answer here (maybe it helps ) Nullable var with `?` vs. lateinit var

Essentially, you are never initializing your repository: RepoRepository.

From the code you have written, you won't need an instance of your repository in your activity as well, it should just be created in the constructor of your ViewModel (which has injection)

You are also going to have a similar issue with private lateinit var repoService: GithubRepos; if it's in the constructor of your object, you don't have to declare it again.


This is because you are trying to use the repository before initializing it with an instance without checking its initialization.

When using lateinit nullity cannot be used in that variable.

lateinit var repository: RepoRepository

Then, before using any method of the object, check that it is initialized:

if (::repository.isInitialized) {}

GL