所以这是我要上传到Firebase的课程:
public class Route {
private String uniqueId;
private long routeTime;
private float distance;
private List<Double> lat;
private List<Double> lan;
public Route(){
uniqueId = "null";
this.lat = null;
this.lan = null;
}
public Route (String id ,long time, float distance, List<Double> lat, List<Double> lon){
this.uniqueId=id;
this.routeTime=time;
this.distance=distance;
this.lat=new ArrayList<Double>(lat) ;
this.lan=new ArrayList<Double>(lon) ;
}
以前我没有lat
和lon
列表,只有一个列表包含位置类型对象,列表名称是点。我已更改它,因为Location类没有空构造函数,Firebase无法检索数据。
问题在于,即使在我将数据上传到firebase后进行更改,它“神奇地”将两个列表转移到一个位置列表中,其名称与我在更改之前给出的名称相同。
这是我上传到firebase的代码:
List<Double> lat = new ArrayList<Double>();
List<Double> lon = new ArrayList<Double>();
for (int i=0; i<locationsList.size(); i++){ //locationsList is a list of Location
lat.add(locationsList.get(i).getLatitude());
lon.add(locationsList.get(i).getLongitude());
}
Route temp = new Route(routeUID,(endDate.getTime()-startDate.getTime())/1000,distance,lat,lon);
currRoute.setValue(temp); //currRoute is a database reference
这是locationList的声明:
private List<Location> locationsList;
它的初始化:
locationsList = new ArrayList<Location>();
这是最后一行之后的数据库:
https://i.imgur.com/aVYDl1X.png
这是数据库路径:
Routes = FirebaseDatabase.getInstance().getReference("Routes");
currUserRoutes = Routes.child(FirebaseAuth.getInstance().getCurrentUser().getUid());
currRoute = currUserRoutes.push();
routeUID = currRoute.getKey();
我不知道它如何将双重列表转换为一个位置列表,并希望得到帮助。
答案 0 :(得分:0)
为什么要再次初始化两个ArrayList?尝试一下,也许这就是原因
改变这个:
public Route (String id ,long time, float distance, List<Double> lat, List<Double> lon){
this.uniqueId=id;
this.routeTime=time;
this.distance=distance;
this.lat=new ArrayList<Double>(lat) ;
this.lan=new ArrayList<Double>(lon) ;
}
To This:
public Route (String id ,long time, float distance, List<Double> lat,List<Double> lon){
this.uniqueId=id;
this.routeTime=time;
this.distance=distance;
this.lat=lat;
this.lan=lon;
}