(Kotlin) lateinit property 'VAL variable' has not been initialized

Viewed 13271

Any one have similar problem before?

How can we declare a default variable value for init()?

Below is my code sample,

@Value("\${app.email-config-file: D:\\email\\src\\main\\resources\\email.config}")
private lateinit var emailDir: String 

init {
    log.info("====================================================================================================")
    log.info("Email Config File Dir: ${this.emailDir}")
    log.info("====================================================================================================")
}

Then below exception throw :

Caused by: kotlin.UninitializedPropertyAccessException: lateinit property emailDir has not been initialized

Any solution can share ?

3 Answers
Related