The question may sound weird. I have the following custom Object
that I named ItemUser
:
private UserInfo user_info;
private List<UserAchievement> user_achievements;
Both fields have getters and setters. My Firestore's database looks like this:
I would like to get the List
size instead of re-calling the database and getting the size of the collection from a separated call that would consume much resources and take a lot of time (3-4s).
Firstly I'm getting the data using this:
mDB.collection("COLLECTION_NAME").document("USER_ID").get()
Inside the onCompletedListener
I'm getting the custom object as the following:
ItemUser mUser = task.getResult().toObject(ItemUser.class);
Now, when I'm trying to get the size of the user_achievements
, a NullPointerException
popups saying I can't get the size of a null reference.
Therefore the user_achievements
is null. I think the way I'm defining user_achievements
in my custom Object is the reason for this exception.
The question is: How could this be possible done without recalling the database to count only the size?
I have the main custom Object ItemUser
and its children are 'healthy' except user_achievements
because of the way it's defined - List<UserAchievement>
.
So, any suggestions to overpass this issue?