BookLog Application: Joining the Puzzle Pieces
The day started on a good note, A sea-side walk, 🌊a good breakfast, some more walks towards the harbor, some cycling, and a few good hours in the local library 📚 which I visited for the first time and it was a total treasure hunt..
Today, I continued with BookLog Application and joined some more puzzle pieces. The issue I had yesterday “Error inflating the fragment class” gave me some tough hours but I was able to figure it out on my own.
Puzzle Piece 01:
I got some help from the article, when I realised I am trying to access resources before the fragment view is created. I changed some more code in all classes.
Puzzle Piece 02:
I added view binding to Library Activity as well which I had not added earlier and I replaced Frame Layout in the layout with Fragment Container View.
//declare a variable
private lateinit var binding: ActivityLibraryBinding//in onCreate() method
binding = ActivityLibraryBinding.inflate(layoutInflater)
setContentView(binding.root)
Joining these two puzzle pieces fixed that inflate fragment error. Now I was left with implementing logic to the Add Book Fragment and that took few good hours to figure out.
I had implemented below code to retrieve list of authors to display it to the Dialog Box
Puzzle Piece 03:
The next puzzle piece to figure out was how to cast the string list of authors back to Author Object, so I implemented some more mode in the dialogBox method call.
I declared two global variables which I used in the method
var bookObject = Book()
private val authorsToAdd: RealmList<Author> = RealmList()
This code worked and Author got added successfully.
The next step was to add clickListener to Add Book button to collect inputs from all components and I implemented below:
Now, the last puzzle piece that left my app hanging is coming from click listener on the button, its not able to add the bookObject successfully and throwing below:
D/AddBookFragment: Error adding the bookObject to Database Object is no longer valid to operate on. Was it deleted by another thread?
The code is not deleting the object anywhere, I wonder whats causing it… Last piece to figure out tomorrow.. :)
PS: Please feel free to read “My journey of 100 days” at MongoDB Community Forums ❤