I’m trying to make edits for multiple contacts depending on the user’s contacts saved by countries. But, when trying to access the entry of the map, the warning below appears.
Thank you…
Interface Entry does not have constructors
for ((key, value) in Map.Entry<String, Array<String>> in dialCodes) {
val code = key.uppercase()
val countryName = Locale("", code).displayCountry
if (TextUtils.isEmpty(countryName)) {
Log.w(TAG, "Country name missing for '$code'")
}
for (prefix in value) {
countryList.add(CountryCode(code, countryName, prefix.trim { prefix <= ' ' }))
}
Collections.sort(countryList)
}
>Solution :
Warning message you’re encountering is due to an incorrect usage of the Map.Entry interface
You should iterate through the entries of a map, not directly create entries using the Map.Entry interface.
val dialCodes: Map<String, Array<String>> = mapOf(
// Initialize your map with key-value pairs
)
val countryList = mutableListOf<CountryCode>()
for ((key, value) in dialCodes) {
val code = key.uppercase()
val countryName = Locale("", code).displayCountry
if (TextUtils.isEmpty(countryName)) {
Log.w(TAG, "Country name missing for '$code'")
}
for (prefix in value) {
countryList.add(CountryCode(code, countryName, prefix.trim { it <= ' ' }))
}
}
Collections.sort(countryList)