com.google.firebase.database.Databaseexception

Asked

Viewed 236 times

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?

  • My model class, Cidade c

  • What is the method getKey()? What string appears on key?

  • key is the key generated by firebase it is a private string, so it has a get(), I edited and placed the part that takes the database data

  • @Victorstafusa forgot to mention, that the variable bairro is a class

  • banco.updateChildren(postValues); in place of banco.updateChildren(childUpdates); functionary?

  • No, make that mistake Can't convert object of type java.util.ArrayList to type Cidade

Show 2 more comments

1 answer

2


The problem was that the variable key was null, failed to assign the firebase generated key

Browser other questions tagged

You are not signed in. Login or sign up in order to post.