1

ArrayList in the below code gives unresolved reference. The IDE recommends possible import solution import of java.util.arraylist. This does not resolve the issue.

I checked the source website code and kotlin.collections arraylist import will fix the issue. Somehow the latter import is not showing up in project files.

What import library am I missing? Only java dependency is being shown in the autocomplete and kotlin one is missing. The source github url is linked below for build.gradle file if needed.

CharactersAdapter.kt

class CharactersAdapter(private val listener: CharacterItemListener) : RecyclerView.Adapter<CharacterViewHolder>() {

    interface CharacterItemListener {
        fun onClickedCharacter(characterId: Int)
    }

    private val items = ArrayList<Character>()

    fun setItems(items: ArrayList<Character>) {
        this.items.clear()
        this.items.addAll(items)
        notifyDataSetChanged()
    }

https://github.com/sberoch/RickAndMorty-AndroidArchitectureSample

1 Answer 1

1

kotlin.collections.ArrayList is the import you're looking for. Make sure kotlin-stdlib is on your classpath - recent versions of the Kotlin Gradle plugin should be adding that dependency automatically.

Sign up to request clarification or add additional context in comments.

5 Comments

apply plugin: 'kotlin-android' and implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" is added in the gradle build but the import doesn't show up.
Do you mean it doesn't show up in the auto-complete menu? What happens if you try to add it manually and build the project?
Yeah it doesn't show up in autocomplete menu. I try to add it manually, it gives compile errors. Modifying the build gradle with removing ' dataBinding{ enabled = true }' resolved the issue. I had added that earlier and removed it to solve the issue.
Yes. app and library plugin seems to add kotlin stdlib automatically, but there is something odd in android-library plugin in compileSDK and targetSDK version 33. It does not, so kotlin.collections.mutableListOf comes unresolved. But is you just open AndroidStudio and compile you main app-project, everything goes OK and you can run result in a devfice. You see, that kotlin.collections.mutableListOf is unresolved in next step you do, for instance when you a class file in android-library module.
Hmm.. logs show that appcompat-1.7.0 is too new for compileSDK and targetSDK version 33, do don't upgrade to it, even if Adroid-Studio suggest to do so, if you don't use SDK 34.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.