DatabaseException: Can't convert object of type java.lang.String to type

前端 未结 7 666
北海茫月
北海茫月 2020-12-03 18:50

I\'ve looked at a few other answers for similar problems but don\'t understand why mine isn\'t working.

I\'m trying to get my app to read commands from Firebase and

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 19:20

    I faced a similar issue where I could not retrieve the data from the database; having a DatabaseException error with a message

    can't convert from this type to that type.

    The mistake I was making was I was writing incorrectly to the database. I wrote something like ...

    mdatabaseReference.setValue(myObject)
    

    instead of

    mdatabaseReference.child(myObject.getId()).setValue(myObject)
    

    So essentially the answer I am suggesting is: you should ensure your data is written correctly to the database at the right node in the JSON tree if not you would likely get this kind of error when you are reading from the database.

提交回复
热议问题