Skip to content
Advertisement

How to retrieve a list of custom objects from Cloud Firestore in Android

I posted before but was not aware of the post standards for questions, so I have reformatted with code to back my issue.

I’m working on an app that uses Google Maps to take you on local tours and keep track of which Landmarks you have visited.

I have managed to write to the database (As shown in picture), but every time I try to read from the database, it claims that ulandmarks is null and I’m trying to call .toString() on a null object reference.

Here I have a Collection(“users”), a Document(uID), and a Field(“userLandmarks”) which contains an array of custom LandMark Objects.

Here I have a Collection("users"), a Document(uID), and a Field("userLandmarks") which contains an array of custom LandMark Objects

I just want to take the list of userLandmarks for the current user and load them into a local list that I can use to populate a Google Map, but I can only retrieve a List of Map<String,Object>.

Here is what I have tried and my Landmark class:

JavaScript

Please help.

Advertisement

Answer

You are getting the following error:

call .toString() on a null object reference

Because you are trying to get a landmarks list that does not exist. The list in the database is called userLandmarks and not landmarks. To solve this issue, you should change the name of the field in the class to match the one in the database.

JavaScript

I also wrote an article that you might be interested in:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement