R
R
retr02017-10-21 20:45:27
Java
retr0, 2017-10-21 20:45:27

FirebaseDatabase error: failed to convert Hashmap to String in Android app, how to fix?

Can't get child value via ValueEventListener.
Error: 59eb86c22a115814532651.png
My FirebaseDatabase: 59eb86e74e3e3419718337.png
Code:

DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference();
        DatabaseReference ref = databaseReference.child(path);

        ref.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {

                String value = dataSnapshot.getValue(String.class);

                ClipboardManager clipboard = (ClipboardManager) getApplicationContext().getSystemService(CLIPBOARD_SERVICE);
                clipboard.setText(value);
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {


            }

Swears exactly on the line
String value = dataSnapshot.getValue(String.class);

It is worth noting that with this code:
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference();
            DatabaseReference ref = databaseReference.child(path);

            ClipboardManager clipboard = (ClipboardManager) getApplicationContext().getSystemService(CLIPBOARD_SERVICE);

            String data = clipboard.getText().toString();
            ref.setValue(data);
everything is in order, although the DatabaseReference are the same. I can not understand what the problem is, I will be grateful for the help.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Denis Zagaevsky, 2017-10-21
@zagayevskiy

data is not a string, but a hashmap, as they write to you in the logs.

A
aol-nnov, 2017-10-21
@aol-nnov

I have one word for you: debugger.
and soon a lot will become clear!

V
Vadim Raksha, 2017-10-31
@hasdfa

Firebase returns hashmap with one line
Key: uzmtn
Value: data
If you need a line at once, then it's like this:

DatabaseReference ref = databaseReference.child(path).child("uzmtn");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question