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

3 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.

5 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.
1 Like

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.

1 Like

Создал новый проект. Скопировал каждый файл из ранее скаченного документа по этой книге. Почистил все данные из эмулятора(сбросил 8 гигов веса). Снова загрузил базу данные в эмулятор. И знаете что… Всё равно список пуст! Это фиаско, ребят :neutral_face:

cleared all use “requiresPolice”, clean and rebuild project, delete device in Device manager, add new device (pixel 4 api 30), upload “database” - success!

1 Like

Thank you! This answer deserves upvotes because the problem isn’t obvious and probably many people did the challenge without realizing the implication it would have on the database.

same, I run the app and I get this error message
E/SQLiteLog: (283) recovered 9 frames from WAL file /data/data/com.bignerdranch.android.criminalintent/databases/crime-database-wal

I tried every mentioned step in these posts and for me problem was solved by cleanin RAM from all apps and restart the app (NOT reinstall)