com.google.firebase.database.DatabaseException

5

I looked for this error and found nowhere, just some resemblances but not this:

  

com.google.firebase.database.DatabaseException: Maps with non-string keys are not supported

Controller (where 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 method toMap() is):

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;
    }
}
    
asked by anonymous 16.11.2017 / 20:28

1 answer

3

The problem was that the variable key was null , it was not necessary to assign the key generated by firebase

    
19.11.2017 / 19:40