Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将数据从firebase恢复到android?_Android_Firebase_Firebase Realtime Database - Fatal编程技术网

如何将数据从firebase恢复到android?

如何将数据从firebase恢复到android?,android,firebase,firebase-realtime-database,Android,Firebase,Firebase Realtime Database,我想要读取数据,以构建一个可以为我的项目显示的对象 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

我想要读取数据,以构建一个可以为我的项目显示的对象

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.softtimcurpmontro E/RecyclerView:未连接适配器;跳过布局10-10

22:33:01.763 13269-13269/com.example.montero.softtimcurpmontro E/RecyclerView:未连接适配器;跳过布局10-10

22:33:01.953 13269-13269/com.example.montero.softtimcurpmontro E/AndroidRuntime:致命异常:主 进程:com.example.montero.softtimcurpmontro,PID:13269
com.google.firebase.database.DatabaseException:类com.example.montero.softtimcurpmontro.Curp缺少没有参数的构造函数


您不需要使用该构造函数。如果变量名称与firebase节点值相同,则可以为变量赋值。 试试这个:

database.limitToLast(1).addChildEventListener(new ChildEventListener() {
                @Override
                public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                    Curp value=dataSnapshot.getValue(Curp.class);
                    //Use this object
                }
            });

您不需要使用该构造函数。如果变量名称与firebase节点值相同,则可以为变量赋值。 试试这个:

database.limitToLast(1).addChildEventListener(new ChildEventListener() {
                @Override
                public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                    Curp value=dataSnapshot.getValue(Curp.class);
                    //Use this object
                }
            });

我唯一需要的是在类Curp中构建一个空conditructor,并在MainActivity中创建一个Curp值

database.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            Curp value=new Curp();
            value=dataSnapshot.getValue(Curp.class);
            lista.add(value);
            cupadapter=new CurpAdapter(lista);
            reciclador.setAdapter(cupadapter);
        }

}

我唯一需要的是在类Curp中构建一个空conditructor,并在MainActivity中生成一个Curp值

database.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            Curp value=new Curp();
            value=dataSnapshot.getValue(Curp.class);
            lista.add(value);
            cupadapter=new CurpAdapter(lista);
            reciclador.setAdapter(cupadapter);
        }

}

看起来您已经具备了恢复/检索数据的基础知识。您在哪一部分遇到困难?要恢复信息并生成对象Curp,但第二个代码不起作用,代码失败当应用程序崩溃时,logcat中应该有错误和堆栈跟踪。请编辑您的问题以包含该信息。在side Crup model类中创建一个空构造函数,并在将适配器设置为recyclerview之前对其进行初始化。看起来您已经具备了恢复/检索数据的基础知识。您在哪一部分遇到困难?要恢复信息并生成对象Curp,但第二个代码不起作用,代码失败当应用程序崩溃时,logcat中应该有错误和堆栈跟踪。请编辑您的问题以包含该信息。在side Crup模型类中创建一个空构造函数,并在将适配器设置为recyclerview.die(Curp value=dataSnapshot.get value(Curp.class)com.example.montero.softtimcurpmontero.MainActivity$1.onChildaded(MainActivity.java:48)之前对其进行初始化Curp缺少一个没有参数的构造函数如果我的答案对你有帮助,请投上一票。我回答了你的第一个问题(更新前)在Curp value=dataSnapshot.get value(Curp.class)com.example.montero.softtimcurpmontro.MainActivity$1.onChildaded(MainActivity.java:48)Curp缺少一个没有参数的构造函数如果我的回答对你有帮助,请投上一票。我回答了你的第一个问题(更新前)