gpt4 book ai didi

java.lang.RuntimeException : Could not deserialize object. 无法将 java.lang.Long 类型的值转换为 boolean 值

转载 作者:太空狗 更新时间:2023-10-29 13:04:55 24 4
gpt4 key购买 nike

我有一个大问题。使用 Android Emulator 运行应用程序效果很好,但是当我将应用程序放在真实手机上时,出现此错误:

java.lang.RuntimeException: Could not deserialize object. Failed to convert value of type java.lang.Long to boolean (found in field 'imp')

我的 Firebase 数据没问题,'imp' 字段是数据库中的 boolean 值,所以我要检索的是来自数据库的 boolean 值并将其存储在 boolean 变量中。当数据作为 boolean 值从 Firebase 发送时,它怎么能说我收到了一个 Long?

为什么只有在真实手机上才会出现这种情况

现在我真的不明白为什么在 Android Emulator 中运行良好,而在真实手机中安装该应用程序却出现此错误。

这是我正在处理数据的适配器:

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;}

我在 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();

日志:

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)

最佳答案

下面一行代码:

java.lang.RuntimeException: Could not deserialize object. Failed to convert value of type java.lang.Long to boolean (found in field 'imp')

准确告诉您问题所在。您的 imp 属性在您的模型类中声明为 Boolean 但是当您尝试从数据库中获取此属性的值时,您得到的是 Long。在 Java 中无法将 Long 转换为 Boolean

要解决这个问题,您需要清除数据库并添加新数据,其中 imp 属性将保存一个 Boolean 值,就像在您的模型类中一样,而不是 值。

关于java.lang.RuntimeException : Could not deserialize object. 无法将 java.lang.Long 类型的值转换为 boolean 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49614685/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com