I have a firebase object that looks like this
posts: {
-Kc6CT_CF--kVYApIhD9: {
-comments: {
-Kc6CkgQ8-5OztuqHqdS {
text: "Text here",
timestamp: 1486179732382,
user: {
"username": "user1",
"email": "[email protected]"
}
}
},
"lat": "37.8136",
"lng": "144.9631"
}
}
And I have a POJO that looks like this:
public class Post {
private Comment comments;
private double lat;
private double lng;
private String text;
private String timestamp;
private Motorist user;
public Post() { }
public Comment getComments() {
return comments;
}
public void setComments(Comment comments) {
this.comments = comments;
}
public double getLat() {
return lat;
}
public void setLat(double lat) {
this.lat = lat;
}
public double getLng() {
return lng;
}
public void setLng(double lng) {
this.lng = lng;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public Motorist getUser() {
return user;
}
public void setUser(Motorist user) {
this.user = user;
}
public static class Comment {
String text;
String timestamp;
Motorist user;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public Motorist getUser() {
return user;
}
public void setUser(Motorist user) {
this.user = user;
}
}
}
Here's the code where I loop in my posts object:
Map<String, Post> td = new HashMap<String, Post>();
for(DataSnapshot postSnapshot : dataSnapshot.getChildren()){
Post post = postSnapshot.getValue(Post.class);
//for (DataSnapshot commentSnapshot : postSnapshot.child("comments").getChildren()) {
// System.out.println(commentSnapshot.getValue());
//}
td.put(postSnapshot.getKey(), post);
Toast.makeText(MapsActivity.this, postSnapshot.getValue().toString(), Toast.LENGTH_SHORT).show();
}
I am using the addValueEventListener. Now, my problem is I cant get the data in comments object. When I run the debugger my comments object is null. What am I missing? Or is there something wrong with my POJO?