Firebase returning null but data exists

Viewed 397

I've spent hours looking for the reason why my code isn't retrieving the filed "firstName" from this structure X :/

Firebase structure

When I'm in debug I can see that Firebase retrieves all the other fields at the same level as "firstName" but this last one is always null, even though it has valid data in it.

Debugged object

This is the line where I'm creating FirestoreRecyclerOptions:

FirestoreRecyclerOptions<X> optionsFirestore = new FirestoreRecyclerOptions.Builder<X>().setQuery(queryFirestore, X.class).build();

I'm a beginner in Android and I'll appreciate any help / explanation.

Thank you in advance for your help !

EDIT:

Here's my queryFirestore:

queryFirestore = FirebaseFirestore.getInstance().collection("idea").whereEqualTo("uid", currentUser.getUid());

And the X class is a POJO containing the data structure:

public class X {

public String uid;
public String avatar;
public String firstName;
public String lastName;
public Integer age;
public String title;
public String category;
public String location;
public String comment;

public X() {
}

public X(String uid, String avatar, String firstName, String lastName, Integer age, String title, String category, String location, String comment) {
    this.uid = uid;
    this.avatar = avatar;
    this.firstName = firstName;
    this.lastName = lastName;
    this.age = age;
    this.title = title;
    this.category = category;
    this.location = location;
    this.comment = comment;
}

public String getUid() {
    return uid;
}

public void setUid(String uid) {
    this.uid = uid;
}

public String getAvatar() {
    return avatar;
}

public void setAvatar(String avatar) {
    this.avatar = avatar;
}

public String getFirstName() {
    return firstName;
}

public void setFirstName(String firstName) {
    firstName = firstName;
}

public String getLastName() {
    return lastName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}

public Integer getAge() {
    return age;
}

public void setAge(Integer age) {
    this.age = age;
}

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

public String getCategory() {
    return category;
}

public void setCategory(String category) {
    this.category = category;
}

public String getLocation() {
    return location;
}

public void setLocation(String location) {
    this.location = location;
}

public String getComment() {
    return comment;
}

public void setComment(String comment) {
    this.comment = comment;
}
}
1 Answers

Problem is in setFirstName():

public void setFirstName(String firstName) {
    firstName = firstName;
}

Try changing it to:

public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

That's why ...

Related