0
I’m trying to get lat e lang which is saved on firebase and recover on map, mPost_key is the uid
user , this code works, more than this error when I put mPost_key , we use this same method mDatabase.child(mPost_key)
activity to bring other user information and also works
Citation 03-06 19:53:11.270 29642-29642/com.robertoc.meublogclash E/UncaughtException: com.google.firebase.database.DatabaseException: Can't convert object of type java.lang.String to type com.robertoc.meublogclash.User at com.google.android.gms.Internal.zzbtg.zze(Unknown Source) at com.google.android.gms.Internal.zzbtg.zzb(Unknown Source) at com.google.android.gms.Internal.zzbtg.zza(Unknown Source) at com.google.firebase.database.Datasnapshot.getValue(Unknown Source) at com.robertoc.meublogclash.Profile$1.onChildAdded(profile.java:128) at com.google.android.gms.Internal.zzbox.zza(Unknown Source) at com.google.android.gms.Internal.zzbqx.zzZS(Unknown Source) at com.google.android.gms.Internal.zzbra$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:5585) at java.lang.reflect.Method.invoke(Native Method) at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:730) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:620) 03-06 19:53:11.503 29642-29642/com.robertoc.meublogclash E/Androidruntime: FATAL EXCEPTION: main Process: com.robertoc.meublogclash, PID: 29642 com.google.firebase.database.Databaseexception: Can’t Convert Object of type java.lang.String to type com.robertoc.meublogclash.User at com.google.android.gms.Internal.zzbtg.zze(Unknown Source) at com.google.android.gms.Internal.zzbtg.zzb(Unknown Source) at com.google.android.gms.Internal.zzbtg.zza(Unknown Source) at com.google.firebase.database.Datasnapshot.getValue(Unknown Source) at com.robertoc.meublogclash.Profile$1.onChildAdded(profile.java:128) at com.google.android.gms.Internal.zzbox.zza(Unknown Source) at com.google.android.gms.Internal.zzbqx.zzZS(Unknown Source) at com.google.android.gms.Internal.zzbra$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:5585) at java.lang.reflect.Method.invoke(Native Method) at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:730) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:620) 03-06 19:53:11.562 1270-1399/? E/GED: Failed to get GED Log Buf, err(0)
mDatabase = FirebaseDatabase.getInstance().getReference().child("Users");
mPost_key = getIntent().getExtras().getString("uidusuario");
mDatabase.child(mPost_key).addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(com.google.firebase.database.DataSnapshot dataSnapshot, String s) {
User childUser = dataSnapshot.getValue(User.class);
LatLng childPos = new LatLng(childUser.getLat(), childUser.getLang());
MarkerOptions markerOptions = new MarkerOptions().position(childPos);
Marker marker = mMap.addMarker(markerOptions);
userMarkers.put(dataSnapshot.getKey(), marker);
userMap.put(dataSnapshot.getKey(), childUser);
}
@Override
public void onChildChanged(com.google.firebase.database.DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(com.google.firebase.database.DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(com.google.firebase.database.DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
My Clase User
public class User {
private double lat;
private double lang;
public User(){}
public double getLat() {
return lat;
}
public void setLat(double lat) {
this.lat = lat;
}
public double getLang() {
return lang;
}
public void setLang(double lang) {
this.lang = lang;
}
I don’t understand why without the mPost_key
the code works correctly, in case mPost_key
it is for when entering the profile to bring only the position in the uid map of the mPost_key
or is a single user.
RESOLVEDThe error was in the database had a number in the middle of the lost path causing the error.
The ERROR itself already gives you a clue, "Can’t Convert Object of type java.lang.String"... you are trying to convert an object into a string. Which line is going wrong?
– viana
The line where you declare
mPost_key
it seems to me that you return astring
and the code waitsUser
. Any clue?– Leonardo Pessoa
User childUser = dataSnapshot.getValue(User.class); this is the line a Line error
– Wallace Roberto
mPost_key
behind the user uid of fire base– Wallace Roberto
I don’t know what was going on but I was doing it the right way, re-did it and it worked.. Thank you who replied!
– Wallace Roberto