为什么我的模型类中的int返回null

时间:2020-10-14 10:36:58

标签: java android firebase-realtime-database

我只是想知道为什么我的getTotal_Score()在我的模型类中为null,但是我可以从数据库中成功检索到它...我已经尝试使用大写Integer和普通int,但这是行不通的。 。我也尝试过Long类型,但是我仍然得到一个null变量。.另一件事也让我感到困惑的是,当我使用int类型而不是long时,它不起作用...。这样做很简单:

int score = (int) snapshop.child("Glen Family Medical Centre").child("Total Score");

我只能使以上内容适用于长型...

public class Information {    // variables have to match in firebase database or it will show null
    private String Address;
    private String Name;
    private String Phone_No;
    private String Suburb;
    private String State;
    private String Postcode;
    private String Doctor;
    private int Total_Score;

    @SuppressWarnings("unused")
    public Information() {
    }
    @SuppressWarnings("unused")
    public Information(String address, String name, String phone_No, String suburb, String state, String postcode, String doctor, int total_score) {
        Address = address;
        Name = name;
        Phone_No = phone_No;
        Suburb = suburb;
        State = state;
        Postcode = postcode;
        Doctor = doctor;
        Total_Score = total_score;

    }

    public int getTotal_Score() {
        return Total_Score;
    }

    public void setTotal_Score(int total_Score) {
        Total_Score = total_Score;
    }

    public String getAddress() {
        return Address;
    }

    @SuppressWarnings("unused")

    public void setAddress(String address) {
        Address = address;
    }

    public String getName() {
        return Name;
    }

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

    public String getPhone_No() {
        return Phone_No;
    }

    @SuppressWarnings("unused")
    public void setPhone_No(String phone_No) {
        Phone_No = phone_No;
    }

    public String getSuburb() {
        return Suburb;
    }

    @SuppressWarnings("unused")
    public void setSuburb(String suburb) {
        Suburb = suburb;
    }

    public String getState() {
        return State;
    }

    @SuppressWarnings("unused")

    public void setState(String state) {
        State = state;
    }

    public String getPostcode() {
        return Postcode;
    }

    @SuppressWarnings("unused")

    public void setPostcode(String postcode) {
        Postcode = postcode;
    }

    public String getDoctor() {
        return Doctor;
    }

    @SuppressWarnings("unused")

    public void setDoctor(String doctor) {
        Doctor = doctor;
    }
}

在另一堂课中,我使用了:

Information info = snapshot.getValue(Information.class);
assert info != null;
String txt = "Medical Clinic: " + info.getName() + "Total Score: " + info.getTotal_Score();
list.add(txt);

0 个答案:

没有答案