class 上未找到 setter/field,但变量名称正确

No setter/field found on class but variable names are correct

我正在尝试使用 Firebase 实时数据库实施星级评分系统,但出现以下错误:

No setter/field for rating found on class com.andrea.uncut.ui.Model.Post

我知道当变量的名称与数据库中的名称不同时会发生这种情况,但在这种情况下它们是:

public class Post {
    private String  postID;
    private String  postImage;
    private float  rating;
    private String  title;
    private String  description;
    private String  publisher;

    public Post(String postID, String postImage, float rating, String title, String description, String publisher) {
        this.postID = postID;
        this.postImage = postImage;
        this.rating = rating;
        this.title = title;
        this.description = description;
        this.publisher = publisher;
    }

    public Post() {
    }

    public String getPostid() {
        return postID;
    }

    public void setPostid(String postID) {
        this.postID = postID;
    }

    public String getPostImage() {
        return postImage;
    }

    public void setPostImage(String postImage) {
        this.postImage = postImage;
    }

    public float getRatingScore() { return rating; }

    public void setRatingScore(float rating) {
        this.rating = rating;
    }

    public String getTitle() {
        return title;
    }

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

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getPublisher() {
        return publisher;
    }

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

所有其他变量都工作正常,所以它是否与 float 类型有关?

getRatingScoresetRatingScore 将用于名为 ratingScore 的 属性。

您的 属性 称为 rating,因此需要 getRatingsetRating

私有内部属性与 Firebase 在模型上设置数据时如何看待它们无关 class。

另外,为了保持一致性,postID 应该是 getPostIDsetPostID