I have lateinit property in my Kotlin activity, this is simplified version of that:
class CreateNewListOfQuestions : AppCompatActivity() { lateinit var questionAnswerListOfObjects: ArrayList<QuestionAnswerObject> override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_create_new_list_of_questions) save.setOnClickListener { questionAnswerListOfObjects.add(0, QuestionAnswerObject("question", "answer", 1)) } } } The main problem is that when I generate mobile app and press “Save” button app stops working. Logcat shows this error: “lateinit property questionAnswerListOfObjects has not been initialized”
I was trying many ways to initialize it but these ways did not help to me. How should I properly initialize it? I am plining to add to ArrayList many objects of this class:
class QuestionAnswerObject(var question: String, var answer: String, var probability: Int=100) {}