7
votes

Screenshot of the errorTrying to execute the below code :

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        Test().list.contains(1)
    }
}

public class Test {

    ArrayList<Integer> list;

    public ArrayList<Integer> getList() {
        return list;
    }
}

and compilation fails at Test().list.contains(1) with message :

Task :app:compileDebugKotlin FAILED e: /Users/sreejithcr/Documents/MyApplication/app/src/main/java/com/wxample/myapplication/MainActivity.kt: (13, 31): Overload resolution ambiguity: public open fun contains(@Nullable element: Int!): Boolean defined in java.util.ArrayList public open fun contains(@Nullable element: Int!): Boolean defined in java.util.ArrayList

What i understand is compiler finds 2 contains() with exact same signature and not sure which one to call.

gradle config :

ext.kotlin_version = '1.3.41'

classpath 'com.android.tools.build:gradle:3.4.2'

2
i'm facing same error, but Kotlin + Java + Intellij IDEABingLi224
FYI: my problem was that Kotlin version in my dependency list is conflicting to the dependencies of another imported library.BingLi224

2 Answers

4
votes

It is an issue with Android Studios API 29 R2

https://issuetracker.google.com/issues/139041608#comment3

Go Tools -> SDK Manager -> Uninstall Android 9.+, then install it again as Google rolled back R2 so you'll be back to R1

-1
votes

As I read through your code I noticed some conflicts:

First, Test needs a public constructor, which creates the ArrayList, sth. like:

public Test(){ list = new ArrayList<>(); }

Second, make the variable list private, access should only be granted through getter/setter. Third, in method onCreate() try:

new Test().getList().contains(1);