I am making an application, in this application I wrote the country names in strings.xml file. I want to get these country names in my Utils class, but I can't get these strings. I would be glad if you help. My code is below:
class Utils {
private var resources: Resources? = null
private val utils = resources!!
fun getAsiaCountriesFlags(): MutableList<Flag> {
return mutableListOf(
Flag(
R.drawable.asia_turkey,
listOf(
utils.getString(R.string.asia_armenia),
utils.getString(R.string.asia_iran),
utils.getString(R.string.asia_turkey),
utils.getString(R.string.asia_azerbaijan)
),
utils.getString(R.string.asia_turkey)
)
)
}
}
private val utils = resources!! It gives me an error on the this line. The error I'm getting is this:
Process: com.example.flagquizapp, PID: 8949
java.lang.NullPointerException
at com.example.flagquizapp.util.Utils.<init>(Utils.kt:10)
resourcesis null because you never initialized it .