Firebase DatabaseException: Failed to convert value of type java.lang.Long to String

前端 未结 7 1133
挽巷
挽巷 2020-12-01 14:50

com.google.firebase.database.DatabaseException: Failed to convert value of type java.lang.Long to String

is the error I keep getting w

相关标签:
7条回答
  • 2020-12-01 15:28

    Problems

    1. If you are adding values in firebase database manually, the values will be in long data type; for example:


    1. If you are adding values by commands, the values will be saved in the database as string.

    Solution:

    When you are getting the values from database, save the values in default data type. Then, when you want to reuse the value change it into the string by using the toString() method.

    0 讨论(0)
  • 2020-12-01 15:33

    The problem is that you are creating the property "mobile_phone" as a String and on Firebase it is a Long type.

    Change:

    private String mobile_phone;
    

    To:

    private Long mobile_phone;
    
    0 讨论(0)
  • 2020-12-01 15:39

    If you want to access data directly without create any object, You can change datatype with String to long.class

    `String reward = ds.child("reward").getValue(String.class);` 
          to
    `long reward = ds.child("reward").getValue(long.class);`
    

    or

    public String reward;
        to
    public long reward;
    
    0 讨论(0)
  • 2020-12-01 15:40

    Try adding quotes (") around the numbers:

    For example mobile_phone = "1234" instead of mobile_phone = 1234

    Image

    0 讨论(0)
  • 2020-12-01 15:41

    Check if your getters and class/model are equals in firebase database.

    When method .getValue() retrieve datas it compare if signatures are same.

    example:
    In class we have a getLong

    for get value retrieve in firebase database

    0 讨论(0)
  • 2020-12-01 15:45

    Edit all the DB entries by adding double quote like "phone" : "900000000" and it will solve the problem, so e.g.:

    "phone" : 900000000
    "name" : "xxxx",
    "password" : 111111
    

    changed to:

    "phone" : "900000000",
    "name" : "xxxx",
    "password" : "111111"
    
    0 讨论(0)
提交回复
热议问题