Your Second Kotlin Android App - Part 27: Integrating | Ray Wenderlich

This video will show you the process of replacing activity code with a fragment instead.

This is a companion discussion topic for the original entry at

Hello @bdmoakley ! I’ve an issue after Integrating Fragments into Activities.

When I run my app,

  • I click the add button to open Dialog to create a list
  • when I click on Create, my app crashes
  • in Logcat I can see this error
2019-02-28 10:51:38.328 3672-3672/com.example.listmaker E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.listmaker, PID: 3672
    kotlin.UninitializedPropertyAccessException: lateinit property listDataManager has not been initialized
        at com.example.listmaker.ListSelectionFragment.addList(ListSelectionFragment.kt:74)
        at com.example.listmaker.MainActivity$showCreateListDialog$1.onClick(MainActivity.kt:62)
        at android.os.Handler.dispatchMessage(
        at android.os.Looper.loop(
        at java.lang.reflect.Method.invoke(Native Method)

I compared my code with the final code but found no differences…

I tried to put breakpoints on my ListSelectionFragment.onAttach method :

override fun onAttach(context: Context) {
        if (context is OnFragmentInteractionListener) {
            listener = context
            listDataManager = ListDataManager(context)
        } else {
            throw RuntimeException(context.toString() + " must implement OnFragmentInteractionListener")

but it does not go into it ???

Any ideas ?


PS > to emulate, I have a device on API 28

@macsimus Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hello Cecilem and Shogunkaramazov!

You are not the only ones who got stuck in this part, because in this lesson it seems that everything was done.

However it was missing to attach the Fragment to MainActivity via XML and Kotlin code.

Watch the lesson “Showing the Fragment” and you will find the answer.

Best regards.