Java 为什么我的模型类中的int返回null
我只是想知道为什么我的getTotal_Score()在我的模型类中是空的,但我可以从数据库中成功地检索到它…我尝试了大写整数和普通整数,但这不起作用…我也尝试了Long类型,但仍然得到一个null变量..另一件让我困惑的事情是,当我使用int类型而不是Long时,它不起作用。。。。您可以通过执行以下操作以int simple的形式检索数字:Java 为什么我的模型类中的int返回null,java,android,firebase-realtime-database,Java,Android,Firebase Realtime Database,我只是想知道为什么我的getTotal_Score()在我的模型类中是空的,但我可以从数据库中成功地检索到它…我尝试了大写整数和普通整数,但这不起作用…我也尝试了Long类型,但仍然得到一个null变量..另一件让我困惑的事情是,当我使用int类型而不是Long时,它不起作用。。。。您可以通过执行以下操作以int simple的形式检索数字: int score = (int) snapshop.child("Glen Family Medical Centre").chil
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);
问:你说的“不行”到底是什么意思?“int”(Java)不能为“null”。问:我假设“snapshop.child()”是一个拼写错误,应该是“snapshot”。对的问:你能更新你的帖子,给我们看一个“txt”的例子吗?我想我的帖子叫快照,但每次它都返回null。。。。我猜是因为我在每个用户后面都放了一个id来存储值。。。