Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Type Error when adding list to adapter – Android

I am trying to add a list to my adapter but got the following error

private val repository = Repository()
private var songResources = repository.fetchData()
private var songList = songResources.keys.toMutableList()

adapter.submitList(songList)

Error
Type mismatch: inferred type is MutableList<String> but (Mutable)List<SongInfo!>? was expected

Here is my Repository.kt

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

class Repository {
    private var songResources = hashMapOf(
        "Dark Star" to
                SongInfo("Dark Star",
                    R.raw.dark_star_excerpt,
                    "1:30"),
        "What's Mine" to
                SongInfo("What's Mine",
                    R.raw.whats_mine_excerpt,
                    "1:15")
    )
    fun fetchData(): HashMap<String, SongInfo> {
        return songResources
    }

I checked using my IDE by printing songList and got.
[Dark Star, What's Mine]
Which I wanted.

What did I do wrong?

>Solution :

Change

private var songList = songResources.keys.toMutableList()

to

private var songList = songResources.values.toMutableList()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading