0

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

enter image description here

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • See http://stackoverflow.com/questions/32108969/why-do-i-get-failed-to-bounce-to-type-when-i-turn-json-from-firebase-into-java – Anid Monsur Feb 11 '16 at 07:52
  • I am trying to do the same but it is not working – user3186007 Feb 11 '16 at 20:59
  • */ public class add_marker { private String Lat; private String Lang; //private String Adresa; @SuppressWarnings("unused") public add_marker(){ } public String getLat(){return Lat;} public String getLang(){ return Lang;} @Override public String toString() { return "add_marker{Lat='" + Lat +"', Lang='" + Lang +"'}"; } } – user3186007 Feb 11 '16 at 21:04
  • this is the change in the class the object creation is like this 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); // this crash the app } – user3186007 Feb 11 '16 at 21:07

0 Answers0