I have this problem, that I cannot get single value from my firebase json and check it if it is null or not.
Here is my json file:
{ "117500978158564407389":
{
"uid" : "117500978158564407389",
"cat_list" : {
"category_list" : [ {
"cat_name" : "Work"
}, {
"cat_name" : "Health"
}, {
"cat_name" : "Food"
}, {
"cat_name" : "Spare time"
}, {
"cat_name" : "Travel"
} ]
}
}
}
Here is my code in Presenter of MVP where i try to get value of my "uid" in json. But it always shows a null.
@Override
public String getId(String id) {
reference = FirebaseDatabase.getInstance().getReferenceFromUrl("https://talisproject-89e62.firebaseio.com/userData/");
reference.child("117500978158564407389").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
CategoryList categoryList = dataSnapshot.getValue(CategoryList.class);
ID = categoryList.getUid();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return ID;
}
}
Here is my POJO class
public class CategoryList implements Serializable {
public List<Category> categoryList;
public List<Category> getCategoryList() {
return categoryList;
}
public void setCategoryList(List<Category> categoryList) {
this.categoryList = categoryList;
}
public CategoryList catList;
public String uid;
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public CategoryList(CategoryList catList, String uid) {
this.catList = catList;
this.uid = uid;
}
}
And Here where I call my Presenter function, it always shows a null. Does anyone knows, why it always shows a null and how can I get this value?
ID = interPresenter.getId(uid);