我用FirebaseRecyclerAdapter使用名爲「Spacecraft」的模型類獲取「Pro」的所有孩子,現在我想檢索所有候選人到Pro的孩子,如「1」沒有找到Android的setter /字段Firebase
我創建了一個公共靜態「candidat」到「航天器」和我使用的getter和setter方法,但仍是同樣的錯誤
這是我的數據庫:
這是模型類
public class Spacecraft{
private String name;
private String desc;
private String last;
private candidat candidat;
public Spacecraft.candidat getCandidat() {
return candidat;
}
public void setCandidat(Spacecraft.candidat candidat) {
this.candidat = candidat;
}
public Spacecraft() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getLast() {
return last;
}
public void setLast(String last) {
this.last = last;
}
public static class candidat{
private String info;
private String namecandid;
public candidat(){}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
public String getNamecandid() {
return namecandid;
}
public void setNamecandid(String namecandid) {
this.namecandid = namecandid;
}
}
}
這是我FirebaseRecyclerAdapter
@Override
protected void onStart() {
super.onStart();
FirebaseRecyclerAdapter<Spacecraft, candidatviewholder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Spacecraft, candidatviewholder>(
Spacecraft.class,
R.layout.candidat,
candidatviewholder.class,
query){
@Override
protected void populateViewHolder(candidatviewholder viewHolder, Spacecraft model, int position) {
viewHolder.setName1(model.getCandidat().getNamecandid());
viewHolder.setInfo1(model.getCandidat().getInfo());
}
};
rv.setAdapter(firebaseRecyclerAdapter);
}
錯誤代碼:
No setter/field for key1 found on class com.example.ilyas.evotingapplication.Spacecraft$candidat
靜態類不能有構造函數 – uguboz
我刪除了構造函數,但仍然是相同的錯誤:/ @uguboz –
不刪除構造函數。從candidat類刪除靜態。並在航天器通過呼籲新的候選人()設置候選人。 – uguboz