user5125506
user5125506

Reputation: 45

returning 2 json values from firebase but one of them is always null? Why?

I'm not an experienced android app developer this only my first app, with that said here is my problem. I am taking the value of "company_name" from the manager's Json area by calling the dataSnapshot from addListenerForSingleValueEvent and than putting the value into the the recipient's Json area(I'm also storing the manager's id "manager_id" in the recipient's Json area), so far that works OK. The problem now is reading the value "company_name" from the recipient's area to populate it in a list using firebaseUI, for some rason I can't figure out why "manager_id" is returned as as a string but "company_name" is null. Here is the code: Getting the value for the "company_name":

mManagersCompany.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(com.google.firebase.database.DataSnapshot dataSnapshot) {
            companyName = dataSnapshot.getValue(String.class);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

Storing it in the recipient's area:

Map<String, Object> info = new HashMap<>();
info.put("company_name", companyName);
info.put("manager_id", manager_id);
mListOfManagers.push().updateChildren(info);

object:

public class CompanyItem {
private String company_name;
private String manager_id;

public CompanyItem(){}

public CompanyItem(String company_name, String manager_id){
    this.company_name = company_name;
    this.manager_id = manager_id;
}

public String getCompanyName() {
    return company_name;
}

public void setCompanyName(String companyName) {
    this.company_name = companyName;
}

public String getManager_id() {
    return manager_id;
}

public void setManager_id(String manager_id_entering) {
    this.manager_id = manager_id_entering;
}

}

retrieve "manager_id" and "company_name" with populateViewHolder of firebaseUI:

@Override
                protected void populateViewHolder(CompanyViewHolder viewHolder, CompanyItem model, int position) {
                    viewHolder.hText.setText(model.getCompanyName());
                    viewHolder.mText.setText(model.getManager_id());
                }

Here is part of the recipient's Json in firebase database:

{  "-KYVoYBRD4UEBL6GYKD_" : 
    {
    "company_name" : "Dude Company",
    "manager_id" : "a1b2c3d4"
    }
}

Why does it return "a1b2c3d4" for the "manager_id" but null for "company_name"? I tried so many different things but I wasn't successful, and I searched through stackoverflow for an answer but couldn't find one that is close to my problem. Can anyone help please?

Upvotes: 0

Views: 58

Answers (1)

Scary Wombat
Scary Wombat

Reputation: 44834

As per my comment

change your setter/getter for company_name to match the format of manager_id –

for example

getCompanyName() to getCompany_name()

Upvotes: 2

Related Questions