error to get firebase node data in android studio

0

Hello I hope you can help me .. I have a bd in firebase I want to list what contains companies but it shows me this error

This is my code to obtain the data

FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference empresaRef = database.getReference(FirebaseReference.EMPRESAS_REFERENCE);
    empresaRef.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            ArrayList<String> listtadoEmpresa = new ArrayList<>();

            for(DataSnapshot nodo : dataSnapshot.getChildren()) {
                Empresa empresa= nodo.getValue(Empresa.class);
                String nombre = empresa.getNombre();
                listtadoEmpresa.add(nombre);
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.e("ERROR ", databaseError.getMessage());
        }
    });

and this is the firebase bd

    
asked by Erick Sánchez Chávez 22.09.2018 в 22:57
source

1 answer

0

Hi, you could try this code, let me know anything

FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference empresaRef = database.getReference().child(FirebaseReference.EMPRESAS_REFERENCE);
empresaRef.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {

        ArrayList<String> listtadoEmpresa = new ArrayList<>();

        for(DataSnapshot nodo : dataSnapshot.getChildren()) {
            Empresa empresa= nodo.getValue(Empresa.class);
            String nombre = empresa.getNombre();
            listtadoEmpresa.add(nombre);
        }
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {
        Log.e("ERROR ", databaseError.getMessage());
    }
});

Explanation: If you want to enter companies, this is a child of your root therefore after calling getReference() you have to put .child("nombre del hijo") which is where is "your list of companies".

    
answered by 23.09.2018 / 07:14
source