无法解析方法'AddSnapshotListener(Firebase.firestore方法)

时间:2018-08-20 21:25:47

标签: android firebase google-cloud-firestore

我正在Android Studio上运行一个项目并使用Firestore,因此我正在构建“ Feed”(显示所有食谱),并从Firestore收到有关AddSnapshotListener方法的奇怪错误

protected void onStart() {
    super.onStart();
    recipeRef.addSnapshotListener(this, new EventListener<QuerySnapshot>() {
        @Override
        public void onEvent(QuerySnapshot queryDocumentSnapshots, FirebaseFirestoreException e) {
            if (e != null) {
                return;
            }

            String data = "";

            for (QueryDocumentSnapshot documentSnapshot : queryDocumentSnapshots) {
                RecipeC recipe = documentSnapshot.toObject(RecipeC.class);
                recipe.setTitle(documentSnapshot.getId());

                String rtitle = recipe.getRtitle();
                String rclass = recipe.getRclass();
                String body = recipe.getBody();
                String publisher = recipe.getPublisher();



                data += "Titulo: " + rtitle + "\nClase: " + rclass + "\nCuerpo: " + body + "\nPublicador:" + publisher;
            }

            textViewfdata.setText(data);
        }
    });
}

完成我的数据查询并且AS无​​法从RecipeC识别配方对象时显示。

我将附加我的RecipeC Java类

package com.sergioa.ut.test;
public class RecipeC {
    String rtitle;
    String body;
    String rclass;
    String publisher;

    public RecipeC(){

    }

    public RecipeC(String rtitle, String rclass, String body, String publisher) {
        this.rtitle = rtitle;
        this.rclass = rclass;
        this.body = body;
        this.publisher = publisher;
    }


    public String getRtitle() { return rtitle; }

    public void setTitle(String rtitle) { this.rtitle = rtitle; }

    public String getBody() { return body; }

    public void setBody(String body) { this.body= body; }

    public String getRclass() { return rclass; }

    public void setRclass(String rclass) { this.rclass = rclass; }

    public String getPublisher() { return publisher; }

    public void setPublisher(String publisher) { this.publisher = publisher; }
}

`

1 个答案:

答案 0 :(得分:0)

我摆脱了在每个字符串中正确调用类的错误,我注意到它们不是RecipeC上显示的对象配方的名称。 RecipeC配方= documentSnapshot.toObject(RecipeC.class);