4
I looked for that mistake and I didn’t find it anywhere, just a few similar but not this:
com.google.firebase.database.Databaseexception: Maps with non-string Keys are not supported
Controller (where the error is):
final DatabaseReference banco = db.getReference("cidade");
//Pega os dados do banco
banco.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
arrayNome.clear();
for(DataSnapshot data: dataSnapshot.getChildren()){
Cidade c = data.getValue(Cidade.class);
c.setKey(data.getKey());
arrayNome.add(c);
}
adapterNome.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
String key = c.getKey();
Map<String, Object> postValues = c.toMap();
Map<String, Object> childUpdates = new HashMap<>();
childUpdates.put(key, postValues);
banco.updateChildren(childUpdates); // <- ESSA LINHA
Model (where the method is toMap()
):
public class Cidade {
private String key;
private String nome;
private String passagem;
private ArrayList<Bairro> bairro;
public Map<String, Object> toMap() {
HashMap<String, Object> result = new HashMap<>();
result.put("nome", nome);
result.put("passagem", passagem);
result.put("bairro", bairro);
return result;
}
}
What is the variable
c
?– Victor Stafusa
My model class,
Cidade c
– Costamilam
What is the method
getKey()
? What string appears onkey
?– Victor Stafusa
key
is the key generated by firebase it is a private string, so it has aget()
, I edited and placed the part that takes the database data– Costamilam
@Victorstafusa forgot to mention, that the variable
bairro
is a class– Costamilam
banco.updateChildren(postValues);
in place ofbanco.updateChildren(childUpdates);
functionary?– Victor Stafusa
No, make that mistake
Can't convert object of type java.util.ArrayList to type Cidade
– Costamilam