【发布时间】:2017-12-28 20:58:51
【问题描述】:
我已经阅读了大量关于这个主题的报告和问题,但似乎无法弄清楚这一点。我有一个名为 Yard 的 Java 对象类:
public class Yard {
private String id;
private String location;
private long hives;
private String last_visit;
private String photo_url;
private String yard_type;
public Yard(String id, String location, long hives, String last_visit, String photo_url, String yard_type) {
this.id = id;
this.location = location;
this.hives = hives;
this.last_visit = last_visit;
this.photo_url = photo_url;
this.yard_type = yard_type;
}
public Yard() {
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public long getHives() {
return hives;
}
public void setHives(long hives) {
this.hives = hives;
}
public String getLast_visit() {
return last_visit;
}
public void setLast_visit(String last_visit) {
this.last_visit = last_visit;
}
public String getPhoto_url() {
return photo_url;
}
public void setPhoto_url(String photo_url) {
this.photo_url = photo_url;
}
public String getYard_type() {
return yard_type;
}
public void setYard_type(String yard_type) {
this.yard_type = yard_type;
}
@Override
public String toString() {
return "Yard{" +
"id='" + id + '\'' +
", location='" + location + '\'' +
", hives=" + hives +
", last_visit='" + last_visit + '\'' +
", photo_url='" + photo_url + '\'' +
", yard_type='" + yard_type + '\'' +
'}';
}
}
我正在尝试检索用户的码以在回收站视图中显示它们。
这是(到目前为止)我的检索方法:
private List<Yard> getYards(){
final List<Yard> list = new ArrayList<>();
userID = mAuth.getCurrentUser().getUid();
Log.d(TAG,"Getting to getYards()" + userID);
FirebaseDatabase db = FirebaseDatabase.getInstance();
DatabaseReference dbRef = db.getReference().child(getString(R.string.dbname_yards));
Query query = dbRef.child(userID);
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
for (DataSnapshot ds: dataSnapshot.getChildren()){
Yard y = new Yard();
y = dataSnapshot.getValue(Yard.class);
list.add(y);
Log.e(TAG,""+y.toString());
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return list;
}
我已经注释掉了 recyclerview 布局管理器和适配器,因为我似乎无法将数据作为我的 Yard 对象。
我目前收到的错误是:
12-28 15:29:24.109 4984-4984/com.bkbeesites.hivelog W/ClassMapper: No setter/field for yard2 found on class com.bkbeesites.hivelog.Models.Yard
12-28 15:29:24.109 4984-4984/com.bkbeesites.hivelog W/ClassMapper: No setter/field for yard1 found on class com.bkbeesites.hivelog.Models.Yard
12-28 15:29:24.109 4984-4984/com.bkbeesites.hivelog E/YardsFragment: Yard{id='null', location='null', hives=0, last_visit='null', photo_url='null', yard_type='null'}
12-28 15:29:24.109 4984-4984/com.bkbeesites.hivelog W/ClassMapper: No setter/field for yard2 found on class com.bkbeesites.hivelog.Models.Yard
12-28 15:29:24.109 4984-4984/com.bkbeesites.hivelog W/ClassMapper: No setter/field for yard1 found on class com.bkbeesites.hivelog.Models.Yard
12-28 15:29:24.109 4984-4984/com.bkbeesites.hivelog E/YardsFragment: Yard{id='null', location='null', hives=0, last_visit='null', photo_url='null', yard_type='null'}
对不起,如果这是一个烦人的新手问题,但我很难过。提前感谢您的帮助。
【问题讨论】:
标签: java android firebase firebase-realtime-database