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

Discussion in 'Android Questions' started by musaso, Jul 3, 2019.

  1. musaso

    musaso Member Licensed User

    Declaration
    Code:
    Dim DatosFirebase As DatabaseReference    
       DatosFirebase.Initialize(
    "Reference",Firebase.getReference2("/"),"root")
        DatosFirebase.addListenerForSingleValueEvent
        DatosFirebase.keepSynced(
    True)
    Code:
    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

    Code:
    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)
     
    Multiverse app likes this.
  2. DonManfred

    DonManfred Expert Licensed User

    looks like google changed something? Hmmm, need to investigate on weekend
     
  3. musaso

    musaso Member Licensed User

    Old:
    Code:
    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.
     
  4. musaso

    musaso Member Licensed User

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

    Code:
    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
     
    Multiverse app likes this.
  5. DonManfred

    DonManfred Expert Licensed User

    looks good.

    The DataSnapshot is not a AbsObjectWrapper so it does not work this way. t least in the latest version i released.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice