Images not loading from URL by Picasso from Firebase Database

匆匆过客 提交于 2019-11-27 05:32:50

The problem in your code lies in the fact that the name of the fields in your Category class are different than the name of the properties in your database. You have in your Category class a field named Name but in your database I see it as name and this is not correct. The names must match. When you are using a getter named getName(), Firebase is looking for a field named name and not Name. See the lowercase n letter vs. capital letter N?

There are two ways in which you can solve this problem. The first one would be to change your model class by renaming the fields according to the Java Naming Conventions. So you model class should look like this:

public class Category {
    private String name, image;

    public Category() {}

    public Category(String name, String image) {
        this.name = name;
        this.image = image;
    }

    public String getName() { return name; }

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

    public String getImage() { return image; }

    public void setImage(String image) { this.image = image; }
}

Now just remove the current data and add it again using the correct names. This solution will work only if you are in testing phase.

There is also the second approach, which is to use annotations. Because I see that you are using private fields and public getters, you should use the PropertyName annotation only in front of the getter. So your Category class should look like this:

public class Category {
    private String Name, Image;

    public Category(String name, String image) {
        Name = name;
        Image = image;
    }

    public Category() { }

    @PropertyName("name")
    public String getName() { return Name; }

    public void setName(String name) { Name = name; }

    @PropertyName("image")
    public String getImage() { return Image; }

    public void setImage(String image) { Image = image; }
}

Don't also forget to start listening for changes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!