0

I am unable to fetch the data from Firebase to Android. I am using the POJO (Java object class) method to display the values.

This is how I have arranged my data on Firebase:

1

This is my POJO class "MonitoringPojo.java".

public class MonitoringPojo {

Results results;

public Results getResults(){

    return results;

}

public class Results {
    double MaxLat;
    double MaxLng;
    double  MinLat;
    double MinLng;
    String Congestion_Status;


    public double getMaxLat() {
        return MaxLat;
    }

    public double getMaxLng() {
        return MaxLng;
    }

    public double getMinLat() {
        return MinLat;
    }
    public double getMinLng() {
        return MinLng;
    }
    public String getCongestion_Status() {
        return Congestion_Status;
    }
}

}

This is where I am trying to fetch and display the values from the FireBase via that POJO class.

 MonitoringPojo pojo = dataSnapshot.getValue(MonitoringPojo.class);
            double sourceOne = pojo.results.getMaxLat();
            double destinationOne = pojo.results.getMaxLng();
            double sourceTwo= pojo.results.getMinLat();
            double destinationTwo= pojo.results.getMinLng();
            String fetchedColor=pojo.results.getCongestion_Status().toString();
            DrawPolygon2(sourceOne,destinationOne,sourceTwo,destinationTwo,fetchedColor);

But unfortunatley I am getting nothing displayed.

Any help would be appreciated. Thankyou!

AL.
  • 36,815
  • 10
  • 142
  • 281

1 Answers1

0

In order to be able to retrieve the data from your model, you need to create the no argument constructor of the class and also the constructor for each variable. Also you need to provide public setter in the same way you have the getters.

An example is this:

public void setMaxLat(long maxLat) {this.maxLat= maxLat;}

You need to set this setters for all of your variables.

Hope it helps.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • I added the no argument constructor for the class and the setter methods. But now I am getting the following error . " E/UncaughtException: com.firebase.client.FirebaseException: Failed to bounce to type " – Raja Shahroze Abbas Apr 12 '17 at 17:31
  • E/UncaughtException: com.firebase.client.FirebaseException: Failed to bounce to type. – Raja Shahroze Abbas Apr 12 '17 at 17:35
  • Caused by: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "MinLng" (class com.example.shahroze.sdsmap_v1.MonitoringPojo), not marked as ignorable (one known property: "results"]) – Raja Shahroze Abbas Apr 12 '17 at 17:36
  • Please read [this](http://stackoverflow.com/questions/32108969/why-do-i-get-failed-to-bounce-to-type-when-i-turn-json-from-firebase-into-java) post to understand how this works. – Alex Mamo Apr 12 '17 at 17:39
  • Is there everything ok? – Alex Mamo Apr 14 '17 at 08:45
  • I understood the whole format, I even converted my data into that format as suggested. But still I was facing problems. For now I have decided to move ahead. But Thankyou for your continous support! – Raja Shahroze Abbas Apr 15 '17 at 15:27