kotlinkotlin-android-extensionskotlin-extension

Accidental override: The following declarations have the same JVM signature


I'm getting error in Kotlin in this part:

class GitHubRepoAdapter(
    private val context: Context,
    private val values: List<GithubRepo>
) : ArrayAdapter<GithubRepo>(
    context, 
    R.layout.list_item,
    values
)

private val context: Context

In the log it says:

Error:(14, 25) Accidental override: The following declarations have the same JVM signature
(getContext()Landroid/content/Context;):  
    fun <get-context>(): Context  
    fun getContext(): Context!

I'm not able to see what is causing the problem.


Solution

  • This happens because the Kotlin compiler tries to generate a getter for val context declared in your class primary constructor, namely a method getContext(), but the base class ArrayAdapter<T> already has such a method.

    You can solve that by doing one of the following: