List is empty after uploading crime-database

I uploaded the databases folder at data/data/<package-name> and followed the instructions in the “Using LiveData” section. The build succeeds without errors, but the list displayed is empty. Upon logging the size of the list in the observer callback in onViewCreated in CrimeListFragment, I’m getting a list size of zero.

What did I do wrong?

I have uploaded the project here:

Thanks in advance!

I also tried running the app from the solution zip, still nothing (only an empty screen)

Not sure what went wrong, but I created the app from scratch again and it seemed to work this time. Although it was indeed weird that I couldn’t get the solutions zip (AndroidProgramming4e.zip) to work.

Was a solution ever figured out for this? I am running into the same issue… not sure what I’m doing wrong! Tried both the solution zip and created it from scratch again, nothing seems to work.

I do have the same issues here too. My list is empty and here’s my code:
crimeListViewModel.crimeListLiveData.observe(
viewLifecycleOwner,
Observer { crimes →
crimes?.let {
updateUI(crimes)
}

            })

It’s also suggested that the code should be in onCreateView(). Can someone really help resolve this.

Check if the DATABASE_NAME variable is the same as the file in data/data, I had this error because I had a stupid space before the string, if the file doesn’t exist, he will create a new one, without throwing errors

2 Likes

Hi Crysto. I have checked and they are the same. No space. I queried the DB on command prompt and was able to see all the records but the size of the list in CrimeListFragment is still 0. I am going crazy trying to figure out where the disconnect is.

In my case, the problem was caused by the implementation of the challenges in the same application. After removing the requiresPolice field, the application works as expected.

2 Likes

The code should be in onViewCreated().

it worked, I mistakenly typed underscore instead of a hyphen.
Thanks

1 Like

I resolved this by:

  1. Removing requiresPolice filed from Crimes.kt (from previous chapter challenge)
  2. Double checking the name DATABASE_NAME = “crime-database” (in CrimeRepository.kt)
  3. Deleting emulator data, redeploying the app to the emulator (this will create an empty crime-database in the package) and then uploading the database files again to overwrite the empty crime-database.

This happened to me as well. To resolve it, what I did was delete then upload the database again.

I’m not sure what caused the database get reset and have no records in, but restoring the database worked for me.