I am getting the variable isn't initialized . kotlin.UninitializedPropertyAccessException: lateinit property no_cyclevalue has not been initialized. Unable get data from editText to Spinner.
Asked
Active
Viewed 964 times
-1
-
Write something to `no_cyclevalue` before reading it – Ricky Mo Nov 22 '22 at 04:56
-
thanks, Yes, I have done that. I am unable to get the value from editText.I am getting Null. – Nov 22 '22 at 05:03
-
1Welcome to stackoverflow. Pease read [How to ask](https://stackoverflow.com/help/how-to-ask) – Ricky Mo Nov 22 '22 at 05:09
1 Answers
2
Variable needs to be initialized first before you can use it.
lateinit var sampleString: String
fun main() {
// initialize the variable word wi
sampleString = "This is a string"
// now you can use it
Log.d("TAG", sampleString)
}
also in Kotlin 1.2 you can do this to check if lateinit variable has been initialized or not
if (::sampleString.isInitialized) {
Log.d("TAG", sampleString)
}

raquezha
- 283
- 1
- 2
- 13