期望BEGIN_ARRAY,但在第1行167列路径$.progress中是NUMBER



我已经阅读了几个基于这个特定问题的答案。我知道,在我的自定义对象(AssignmentData),它是期望数组,但它实际上是一个数组在firestore与进度的名称为好。这是firestore文档

assignmentId
"irfan 1671299952415"
endTime
"1671991147130"
exStatus
0
game_nameId
2
groupName
"Math 101"
levelId
"1"
number_of_exercises
10
progress
[]

sectionId"1">

My Custom Object

public class Assignmentsdata implements Serializable {
@SerializedName("exStatus")
@Expose
private Integer exStatus;
@SerializedName("groupName")
@Expose
private String groupName;
@SerializedName("teacherId")
@Expose
private String teacherId;
@SerializedName("game_nameId")
@Expose
private Integer gameNameId;
@SerializedName("levelId")
@Expose
private String levelId;
@SerializedName("students")
@Expose
private List<PersonModel> students = null;
@SerializedName("progress")
@Expose
private ArrayList<String> progress = null;
public Integer getExStatus() {
return exStatus;
}
public void setExStatus(Integer exStatus) {
this.exStatus = exStatus;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getTeacherId() {
return teacherId;
}
public void setTeacherId(String teacherId) {
this.teacherId = teacherId;
}
public Integer getGame_nameId() {
return gameNameId;
}
public void setGameNameId(Integer gameNameId) {
this.gameNameId = gameNameId;
}

public ArrayList<String> getProgress() {
return progress;
}
public void setProgress(ArrayList<String> progress) {
this.progress = progress;
}

有一个数组,我期待一个数组,那么是什么导致错误?

DocumentSnapshot document = task.getResult();
try {
Gson gson = new Gson();
String json = gson.toJson(document.getData());
// tried map directly from document but outcome is same.
//Assignmentsdata assignmentsdata = document.toObject(Assignmentsdata.class);
Assignmentsdata assignmentsdata = gson.fromJson(json, Assignmentsdata.class);
if (assignmentsdata != null) {
filtered_invitation_list.add(assignmentsdata);
}
}catch (NullPointerException e){
Log.d("Failure", "No exception here: ", 
}

if (finalI == teachers.size() - 1) {
try {

Error显示在Exception下面而不是上面,它实际上是在获取对象。

consumer.accept(filtered_invitation_list);
} catch (Exception e) {
Log.d("Failure", "Here is get the exception: ", e);
}
}

我在这个代码中收到了上面的错误。

consumer.accept(filtered_invitation_list);
} catch (Exception e) {
Log.d("Failure", "Here is get the exception: ", e);
}
}

但是映射来自firestore的对象没有问题,问题是ViewModel和观察来自firestore的对象列表。我已经在本地保存了一些任务,因为对象结构或字段的不匹配,它在我的Fragment类中给出了错误,但在我的存储库中观察到错误。我知道为什么错误返回到存储库有点棘手。

viewModel.getActiveAssignments.observe(getViewLifecycleOwner(), this::getAssignmentsData);
private void getAssignmentsData(ArrayList<Assignmentsdata> assignmentsdata) {
// get the data saved locally and merge with new incoming. 

最新更新