Home > Back-end >  Android kotlin lateinit property has not been initialized
Android kotlin lateinit property has not been initialized

Time:11-24

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.

CodePudding user response:

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)
}

Similar question

  • Related