Kotlin array function asList() unresolved reference

Issue

I have a code:

fun loadSounds(): List<String> {
    try {
      val soundNames  assets.list(SOUNDS_FOLDER)!!
      Log.d (TAG, "Found ${soundNames.size} sounds")
      return soundNames.asList()
    }
    catch (e: Exception) {
      Log.e(TAG, "Could not list assets", e)
      return emptyList()
    }
  }

I couldn’t compile it, because of error:

Unresolved reference: asList

How can I convert array (array<(out) string!>) to list? And what does array<(out) string!> mean?

Update: I have a promblems with asList(), toList() and split(), they are unresolved references.

Solution

The main reason was not in checking for the nullability, but in the project settings, something was broken (maybe stdlib including or something else). I copy my code and paste it in another empty project, rename it and everething is fine now.

Answered By – Dmitry Fedorov

Leave a Comment