我想从Firebase中提取数据,我有两个数字类型的字段,这些字段导致我出现兼容性问题
数字以外的其他字符数据起作用
package fr.halas.loginhalas.Filter;
import com.google.firebase.firestore.IgnoreExtraProperties;
@IgnoreExtraProperties
public class Affichage {
public static final String FIELD_CREATOR_NAME = "CreatorName";
public static final String FIELD_USERID = "UserID";
public static final String FIELD_MODULE = "Module";
public static final String FIELD_SECTION = "Section";
public static final String FIELD_GROUPE = "Groupe";
private String CreatorName;
private String Module;
private String UserID;
private long Section;
private long Groupe;
public Affichage(String CreatorName,String UserID,String Module, long Section, long Groupe) {
this.CreatorName = CreatorName;
this.UserID = UserID;
this.Module = Module;
this.Section = Section;
this.Groupe = Groupe;
}
public Affichage() {
// empty default constructor, necessary for Firebase to be able to deserialize users
}
public String getCreatorName() {
return CreatorName;
}
public void setCreatorName(String creatorName) {
CreatorName = creatorName;
}
public String getModule() {
return Module;
}
public void setModule(String module) {
Module = module;
}
public String getUserID() {
return UserID;
}
public void setUserID(String userID) {
UserID = userID;
}
public long getSection() {
return Section;
}
public void setSection(long section) {
Section = section;
}
public long getGroupe() {
return Groupe;
}
public void setGroupe(long groupe) {
Groupe = groupe;
}
}
@SuppressLint("SetTextI18n")
public void bind(final DocumentSnapshot snapshot, final OnAffichageSelectedListener listener) {
final Affichage affichage = snapshot.toObject(Affichage.class); // Error is here !
creator.setText(affichage.getCreatorName());
moduleView.setText(affichage.getModule());
groupeView.setText("Groupe: " + affichage.getGroupe());
sectionView.setText("Section: " + affichage.getSection());
错误消息是 05-10 18:00:36.850 19488-19488 / fr.halas.loginhalas E / Android运行时:致命异常:主要 工艺:fr.halas.loginhalas,PID:19488 java.lang.RuntimeException:无法反序列化对象。无法将类型为java.lang.String的值转换为long(在“ Groupe”字段中找到)
答案 0 :(得分:0)
在我的手机上完全删除该应用程序并重新启动编译后,它可以正常启动且没有错误,该应用程序必须提供无效的缓存
答案 1 :(得分:-2)
这两行:
groupeView.setText("Groupe: " + affichage.getGroupe());
sectionView.setText("Section: " + affichage.getSection());
应为:
groupeView.setText("Groupe: " + Long.toString(affichage.getGroupe());
sectionView.setText("Section: " + Long.toString(affichage.getSection());