Android Studio Java错误-无法解析方法'toObject()

时间:2019-02-13 21:08:11

标签: java android firebase

我对Java和Android Studio还是陌生的,遇到以下问题,无法将某人的代码适应我自己的设备。他们在哪里使用DocumentReference,而我正在尝试使用CollectionReference +将documentSnapshot更改为Querysnapshot。

进行修改时,出现以下错误:

  

无法解析方法'toObject()-关于   LocationInformation.class

 private void addMapMarkers(){
    CollectionReference locationsRef = mDb
            .collection("Stop Locations");

locationsRef.get().addOnCompleteListener(new 
OnCompleteListener<QuerySnapshot>() {
        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {

            if(task.isSuccessful()){
                if(task.getResult().toObject(LocationInformation.class) != null){

                    mLocationInformations.add(task.getResult().toObject(LocationInformation.class));
                }
            }
        }
    });

下面是我的位置信息课:

import com.google.firebase.firestore.GeoPoint;

public class LocationInformation {
    private String name;
    private GeoPoint geo;
    private String  avatar;
    private String loc_id;

    public LocationInformation(String name, GeoPoint geo, String avatar, String loc_id) {
        this.name = name;
        this.geo = geo;
        this.avatar = avatar;
        this.loc_id = loc_id;
    }

    public LocationInformation(){

    }


    public String getLoc_id() {
        return loc_id;
    }

    public void setLoc_id(String loc_id) {
        this.loc_id = loc_id;
    }

    public Double getLongitude() {
        return longitude;
    }

    public void setLongitude(Double longitude) {
        this.longitude = longitude;
    }

    private Double longitude;



    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public GeoPoint getGeo() {
        return geo;
    }

    public void setGeo(GeoPoint geo) {
        this.geo = geo;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    @Override
    public String toString() {
        return "LocationInformation{" +
                "name=" + name +
                ", geo=" + geo +
                ", avatar='" + avatar +
                ", loc_id='" + loc_id +
                '}';
    }

}

0 个答案:

没有答案