firebaseandroid-studiofirebase-realtime-databasegetter-setterrating-system

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


I am trying to implement a star rating system using Firebase realtime database and I get the following error:

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

I know this can happen when variables are not named the same as in the database but in this case they are:

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

Database screenshot

All the other variables work fine so could it be anything related to the type being float?


Solution

  • getRatingScore and setRatingScore would be used for a property called ratingScore.

    Your property is called rating, so it would need to be getRating and setRating.

    The private internal properties have nothing to do with how Firebase sees them when setting data on the model class.

    Plus, postID should be getPostID and setPostID for consistency.