Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
693 views
in Technique[技术] by (71.8m points)

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

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

is the error I keep getting when following the docs in attempting to retrieve data to an object for use.

Here is my object model

public class User {

    private String tour_director_key;
    private String last_name;
    private String location_latitude;
    private String tour_id;
    private String photo;
    private String tour_director_name;
    private String middle_name;
    private String location_longitude;
    private String passenger_id;
    private long location_updated;
    private String tour_director;
    private String email;
    private String first_name;
    private String mobile_phone;
    private String td_id;

    public User() {
        // empty default constructor, necessary for Firebase to be able to deserialize users
    }

    public String getTour_director_key() {
        return tour_director_key;
    }
    public String getLast_name() {
        return last_name;
    }
    public String getLocation_latitude() {
        return location_latitude;
    }
    public String getTour_id() {
        return tour_id;
    }
    public String getPhoto() {
        return photo;
    }
    public String getTour_director_name() {
        return tour_director_name;
    }
    public String getMiddle_name() {
        return middle_name;
    }
    public String getLocation_longitude() {
        return location_longitude;
    }
    public String getPassenger_id() { return passenger_id; }
    public String getMobile_phone() { return mobile_phone; }
    public long getLocation_updated() {
        return location_updated;
    }
    public String getTour_director() {
        return tour_director;
    }
    public String getEmail() {
        return email;
    }
    public String getFirst_name() {
        return first_name;
    }
    public String getTd_id() { return td_id; }

}

Data on firebase for user:

IMG HERE and finally the code & line I get the error on is commented.

  Query userDataQuery = Constants.USER_REF.orderByKey().equalTo(mUserId);

  userDataQuery.addValueEventListener(new ValueEventListener() {
      @Override
      public void onDataChange(DataSnapshot dataSnapshot) {
         for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
             //// ERROR COMES FROM THE LINE BELOW ////
             User currentUser = postSnapshot.getValue(User.class);
             Log.i("THE_CURRENT_USER:::", currentUser.toString());
             Log.i("THE_USERS_EMAIL:::", currentUser.getEmail());

             ...

Full Stacktrace:

FATAL EXCEPTION: main
Process: app.timto.co.app, PID: 7453
com.google.firebase.database.DatabaseException: Failed to convert value of type java.lang.Long to String
    at com.google.android.gms.internal.zzaln.zzcc(Unknown Source)
    at com.google.android.gms.internal.zzaln.zzb(Unknown Source)
    at com.google.android.gms.internal.zzaln.zza(Unknown Source)
    at com.google.android.gms.internal.zzaln.zzb(Unknown Source)
    at com.google.android.gms.internal.zzaln$zza.zze(Unknown Source)
    at com.google.android.gms.internal.zzaln$zza.zzcc(Unknown Source)
    at com.google.android.gms.internal.zzaln.zzd(Unknown Source)
    at com.google.android.gms.internal.zzaln.zzb(Unknown Source)
    at com.google.android.gms.internal.zzaln.zza(Unknown Source)
    at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
    at app.timto.co.app.AttendanceActivity$1$1.onDataChange(AttendanceActivity.java:112)
    at com.google.android.gms.internal.zzaie.zza(Unknown Source)
    at com.google.android.gms.internal.zzaje.zzcta(Unknown Source)
    at com.google.android.gms.internal.zzajh$1.run(Unknown Source)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...