2017-04-12 49 views
0

我无法将Firebase中的数据提取到Android。我正在使用POJO(Java对象类)方法来显示值。无法通过Java对象类(POJO)从Firebase检索数据

这是我已经安排在火力地堡我的数据:

1

这是我的POJO类 “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; 
    } 
} 

}

这是我试图获取,并通过该POJO类显示从火力点的值。

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); 

但unfortunatley我没有得到任何显示。

任何帮助,将不胜感激。谢谢!

回答

0

为了能够从model中检索数据,您需要创建类的the no argument constructor以及每个变量的构造函数。你也需要以与获得者相同的方式提供公共setter。

一个例子是这样的:

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

您需要设置这个setter方法所有的变量。

希望它有帮助。

+0

我添加了该类和setter方法的no参数构造函数。但现在我收到以下错误。 “E/UncaughtException:com.firebase.client.FirebaseException:无法反弹以键入” –

+0

你得到的错误是什么? –

+0

E/UncaughtException:com.firebase.client.FirebaseException:无法反弹为键入。 –