Run time error when retrieving JSON data

The line val photoResponse: PhotoResponse? = flickrResponse?.photos

in listing 24.27 fails with an UnitializedPropertyAccessException: lateinit property photos has not being initialized.

Is something missing from the code in Chapter 24?

Have you checked your values?

The code from chapter worked fine for me.
When I stared to do the challenge (adding a custom gson deserializer) Ive received similar error, so maybe check if you copied “FlickrResponse” and “PhotoResponse” classes correctly or your “fetchPhotos()” is exactly as in a book.

I had similar problem when i was doing deserializer challenge. kotling wasn’t happy when i set lateinit variable directly from constructor instead i create instance then i modify lateinit value after instance was created. i hope this was helpful