0
am having an error using Firebaserecycleradapter, at the time of recovering the data from firebase presents this error: "com.google.firebase.database.Databaseexception: Expected a List while deserializing, but got a class java.util.Hashmap"
I saw that it is something related to reading the ID created for each clinic, I am generating a key automatically for each clinic. Can anyone help me with this? How I recover the ids and show all the clinics registered at firebase?
mFirebaseDatabase = FirebaseDatabase.getInstance();
rootReference = mFirebaseDatabase.getReference().child("clinicas");
listaClinicas = new ArrayList<>();
}
@Override
protected void onStart() {
super.onStart();
FirebaseRecyclerAdapter<Clinicas, ViewHolder> firebaseRecyclerAdapter =
new FirebaseRecyclerAdapter<Clinicas, ViewHolder>(
Clinicas.class,
R.layout.adapter_lista_clinicas,
ViewHolder.class,
rootReference
) {
@Override
protected void populateViewHolder(final ViewHolder viewHolder, final Clinicas clinicas, int position) {
final String clinicasIds = getRef(position).getKey();
rootReference.child(clinicasIds).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
viewHolder.setDetails(getApplicationContext(), clinicas.getNomeClinica(), clinicas.getEnderecoClinica(),
clinicas.getBairroClinica(), clinicas.getEstadoCidadeClinica(), clinicas.getTelefoneClinica(), clinicas.getWhatsappClinica(),
clinicas.getFoto2());
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
};
mRecyclerView.setAdapter(firebaseRecyclerAdapter);
}
But how’s your database? In my case I am using Firebaserecycleradapter, I do not understand where and how to recover and set the id so that they can be located the data.
– djalmafreestyler
My database I get by this line " Databasereference tecnicoDb = Firebasedatabase.getInstance(). getReference(). Child("Usuarios"). Child("Clients"). Child(usuarioAtualID). Child("connections"). Child("technicians"); " But since I didn’t use this Firebaserecycleradapter it might be different approach.
– Alucard
Where is declared and how do you receive the data of the variable "userAtualID"? My reference is at the root, but there I have Ids, that gives the problem, I can not find a way to make my reference to reach it and read all children of the id generated automatically with push.
– djalmafreestyler
User private string AtualID; Inside Oncreate: usuarioAtualID = Firebaseuth.getInstance(). getCurrentUser(). getUid(); getCurrentUser(). getUid(); will take the ID of the current logged in user.
– Alucard
I understood, it is because in case you are getting the user id logged in the app, in my case I needed to get to the ids, my recyclerview shows nothing.
– djalmafreestyler
What my code does is: First I create a reference to the database: Databasereference tecnicoDb = Firebasedatabase.getInstance(). getReference(). Child("Usuarios"). Child("Clients"). Child(usuarioAtualID). Child("conexoes"). Child("tecnicos");
– Alucard
Then I create an addListenerForSingleValueEvent to go through all that are in the field I searched for in the reference: for (Datasnapshot tecnico: dataSnapshot.getChildren()){ Fetchtecnicoinformation(tecnico.getKey()); } The Fetchtecnicoinformation method will receive all id’s and then I go through the Database Technicians field once again to display in my Recyclerview.
– Alucard