I have big problem. Runing the app using Android Emulator works good, but when I put the app on a real phone i get this error :
java.lang.RuntimeException: Could not deserialize object. Failed to convert value of type java.lang.Long to boolean (found in field 'imp')
My Firebase data is OK, 'imp' field is a boolean in the database, so what I'm retrieving is a boolean from databae and storing it in a boolean var. How can it say that I receive a Long when the data is sent from Firebase as a Boolean?
Why is this happening only with a real phone?
Now I really don't understand why in Android Emulator works fine and installing the app in a real phone gives me this error.
This is my adapptor who is handling the data:
public class modelNoutati {
String name;
String cont;
Date data;
Boolean imp;
public modelNoutati(){ }
public modelNoutati(String cont, Date data, Boolean imp, String name) {
this.name = name;
this.cont = cont;
this.data = data;
this.imp = imp;
}
public String getName() {return name;}
public void setName(String name) {this.name = name;}
public Date getData() {return data;}
public void setData(Date data) {this.data = data;}
public String getCont() {return cont;}
public void setCont (String cont) {this.cont = cont; }
public Boolean getImp () {return imp;}
public void setImp (Boolean imp) {this.imp = imp;}
I get the issue here on doc.getDocument().toObject(modelNoutati.class)
for (DocumentChange doc : documentSnapshots.getDocumentChanges()){
if(doc.getType() == DocumentChange.Type.ADDED) {
modelNoutati newsInt = doc.getDocument().toObject(modelNoutati.class);
newsL.add(newsInt);
newsAdaptor.notifyDataSetChanged();
Logcat:
Process: projects.nv.umcstudent, PID: 14354
java.lang.RuntimeException: Could not deserialize object. Failed to convert value of type java.lang.Long to boolean (found in field 'imp')
at com.google.android.gms.internal.zzeym.zzc(Unknown Source)
at com.google.android.gms.internal.zzeym.zza(Unknown Source)
at com.google.android.gms.internal.zzeym.zzb(Unknown Source)
at com.google.android.gms.internal.zzeym.zza(Unknown Source)
at com.google.android.gms.internal.zzeym$zza.zza(Unknown Source)
at com.google.android.gms.internal.zzeym.zza(Unknown Source)
at com.google.android.gms.internal.zzeym.zza(Unknown Source)
at com.google.firebase.firestore.DocumentSnapshot.toObject(Unknown Source)
at com.google.firebase.firestore.QueryDocumentSnapshot.toObject(Unknown Source)
at projects.nv.umcstudent.News$1.onEvent(News.java:70)
at projects.nv.umcstudent.News$1.onEvent(News.java:57)
at com.google.firebase.firestore.zzi.onEvent(Unknown Source)
at com.google.android.gms.internal.zzeyn.zza(Unknown Source)
at com.google.android.gms.internal.zzeyo.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
The following line of code:
java.lang.RuntimeException: Could not deserialize object. Failed to convert value of type java.lang.Long to boolean (found in field 'imp')
Tells you exactly what the problem is. Your imp
property is declared in your model class as a Boolean
but when you are trying to get the value of this property from the database you are getting a Long
. There is no way in Java in which you can convert the Long
to a Boolean
.
To solve this, you need to clear your database and add fresh data in which the imp
property will hold a Boolean
value as in your model class, and not a Long
value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With