I have this problem in android using firebase
onChildAdded
function. I want to retrieve some data that I send in android Database in this structure
This is a structure to save marker data Lat, Lang and address or desc,
I want to retrieve in a activity all markers added by user from another activity in my application in real time.
This is the class
public class add_marker {
private String Lat;
private String Lang;
private String Adresa;
@SuppressWarnings("unused")
public add_marker(){}
add_marker(String Lat, String Lang) {
this.Lat = Lat;
this.Lang = Lang;
}
public String getLat(){
return Lat;
}
public String getLang(){
return Lang;
}
}
//////////////////////////////////////////
and the code where I use this class to create the object m1 is: then I want to use the object to re create the markers on the other map activity.
Firebase ref = new Firebase("https://db.firebaseio.com/markera");
ref.addChildEventListener(new ChildEventListener() {
// Retrieve new posts as they are added to the database
@Override
public void onChildAdded(DataSnapshot snapshot, String s) {
add_marker m1 = snapshot.getValue(add_marker.class);
// System.out.println("Lat: " + m1.getLat());
//System.out.println("Lang: " + m1.getLang());
System.out.println("hello");
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
} ......
I am trying to create an object with the data from the database and then load them in a map fragment on the activity one by one each time a child is added, you can check the object m1.
every time I try to run this activity the app crash.