https://kotlinlang.org logo
#android
Title
# android
y

yaakov

07/04/2018, 12:32 AM
So I'm using Google Maps in my Android app for a country picker but I keep getting this error:
Java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
How can I prevent this kind of error? I think the problem comes from here:
Copy code
val address = geocoder.getFromLocation(it.latitude, it.longitude, 1)
val country = address[0].countryCode.toLowerCase()
f

fatih.yalmanbas

07/04/2018, 7:20 AM
Copy code
address.gerOrNull[0]?.countryCode?.toLowerCase().orEmpty()

val country = if (address.isNotEmpty()) address[0].countryCode.toLowerCase() else ""
either one of those