I'm currently working with a room database in my journal app. However, whenever I try to insert a new entry into my app without changing the bitmap variable by picking an image, my app crashes and displays this error.
2020-12-24 22:44:35.296 31023-31023/com.google.gradient.red E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.google.gradient.red, PID: 31023
kotlin.UninitializedPropertyAccessException: lateinit property bitmap has not been initialized
at com.google.gradient.red.fragments.add.addFragment.insertDataToDb(AddFragment.kt:132)
at com.google.gradient.red.fragments.add.addFragment.onOptionsItemSelected(AddFragment.kt:111)
Here is my code:
// I make my bitmap variable
lateinit var bitmap: Bitmap
override fun onAttach(context: Context) {
super.onAttach(context)
var bitmap: Bitmap? = null
}
Line 111 is when I call my insertDataToDb() function, and line 132 is in newData where I'm trying to insert my bitmap variable.