我想讀取數據,建立一個對象,我可以顯示我的項目。我如何從Firebase將數據恢復到android?
public class Curp{
public String curpGen, Nombre, ApPat, apMat, sexo, estado, fecha;
public Curp(String curpGen,String Nombre,String ApPat,String apMat,String fecha,String sexo,String estado){
this.curpGen=curpGen;
this.Nombre=Nombre;
this.ApPat=ApPat;
this.apMat=apMat;
this.fecha=fecha;
this.sexo=sexo;
this.estado=estado;
}
}
在這一部分,我要讀的數據並保存到創建對象curp方法。
我想知道如何用數據構建對象Curp
。
database.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
String curpGen=dataSnapshot.getValue(Curp.class).curpGen.toString();
String nombre=dataSnapshot.getValue(Curp.class).Nombre.toString();
String ApPat=dataSnapshot.getValue(Curp.class).ApPat.toString();
String ApMat=dataSnapshot.getValue(Curp.class).apMat.toString();
String Fecha=dataSnapshot.getValue(Curp.class).fecha.toString();
String sexo=dataSnapshot.getValue(Curp.class).sexo.toString();
String edo=dataSnapshot.getValue(Curp.class).estado.toString();
Curp value=new Curp(curpGen,nombre,ApPat,ApMat,Fecha,sexo,edo);
lista.add(value);
cupadapter=new CurpAdapter(lista);
reciclador.setAdapter(cupadapter);
}
}
22:33:01.533 13269-13269/com.example.montero.softtimcurpmontero E/RecyclerView:否適配器連接;跳過佈局10-10
22:33:01.763 13269-13269/com.example.montero.softtimcurpmontero E/RecyclerView:沒有附加適配器;跳過佈局10-10
22:33:01.953 13269-13269/com.example.montero.softtimcurpmontero E/AndroidRuntime:致命異常:主 工藝:com.example.montero.softtimcurpmontero,PID:13269 COM .google.firebase.database.DatabaseException:類com.example.montero.softtimcurpmontero.Curp缺少無參數的構造函數
看起來你已經有基礎恢復/檢索數據。你有哪些困難? –
恢復信息並建立對象Curp,但第二個代碼不起作用,代碼失敗 – Montero
當應用程序崩潰時,logcat中應該有一個錯誤和堆棧跟蹤。請編輯您的問題以包含該信息。 –