Accidental override: The following declarations have the same JVM signature

Viewed 45288

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.

7 Answers

Change variable name to myContext and will work with you without any problems.

I got a similar error I solved it by removing the null checks from the constructor parameter

From

fun onChildDraw(
    c: Canvas?,
    recyclerView: RecyclerView?,
    viewHolder: RecyclerView.ViewHolder,
    dX: Float,
    dY: Float,
    actionState: Int,

To

fun onChildDraw(
    c: Canvas,
    recyclerView: RecyclerView,
    viewHolder: RecyclerView.ViewHolder,
    dX: Float,
    dY: Float,
    actionState: Int,

Had similar problems, what worked was ensuring that my targetSdkVersion and compileSdkVersion were the same across all modules.

I would like to add something here:

When you name your parameter as context it will collide with the base class parameter name which is also context by default. So changing the name of your parameter will help you.

The return types of the two functions are Context and Context! which are two different things. To fix it, add the exclamation mark to your code.

Related