Android Question [Solved]com.google.firebase.database.DataSnapshot cannot be cast to de.donmanfred.DataSnapshotWrappe

musaso

Member
Licensed User
Declaration
B4X:
   Dim DatosFirebase As DatabaseReference    
   DatosFirebase.Initialize("Reference",Firebase.getReference2("/"),"root")
    DatosFirebase.addListenerForSingleValueEvent
    DatosFirebase.keepSynced(True)
B4X:
Sub Reference_onDataChange(snapshot As Object, tag As Object)
    If AutorizadoFB = False Then Return
    Dim snap As DataSnapshot = snapshot
    Dim m As Map = snap.Value
    Dim FechaFB As Long =  DateUtils.UnixTimeToTicks(m.Get(NombresJson(3)))'timestamp
    Dim per As Period = DateUtils.PeriodBetweenInDays(FechaUDivisas, FechaFB)
        
End Sub
Error after updating to android 28

B4X:
lib2:Raising.. reference_ondatachange()
main_reference_ondatachange (java line: 1935)
java.lang.ClassCastException: com.google.firebase.database.DataSnapshot cannot be cast to de.donmanfred.DataSnapshotWrapper
    at com.modes.conversor.main._reference_ondatachange(main.java:1935)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at anywheresoftware.b4a.BA$2.run(BA.java:370)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5219)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
 

musaso

Member
Licensed User
Old:
B4X:
Sub Reference_onDataChange(snapshot As Object, tag As Object)
    If AutorizadoFB = False Then Return
    Dim snap As DataSnapshot = snapshot  'CHANGE THIS LINE FOR ....
    snap.Initialize(snapshot) 'THIS LINE AND OK

    Dim m As Map = snap.Value
    Dim FechaFB As Long =  DateUtils.UnixTimeToTicks(m.Get(NombresJson(3)))'timestamp
    Dim per As Period = DateUtils.PeriodBetweenInDays(FechaUDivisas, FechaFB)
        
End Sub

I think that in this way it works.
 

musaso

Member
Licensed User
My App had been running a year ago.
Now I have had to change this ..... ??????

B4X:
Sub Reference_onDataChange(snapshot As Object, tag As Object)

    If AutorizadoFB = False Then Return
    Dim snap As DataSnapshot = snapshot  'CHANGE THIS LINE FOR ....
    snap.Initialize(snapshot) 'THIS LINE AND RUN OK
    
End Sub
 
Top