所以我有一个名为Task的自定义ParseObject和另一个名为Group的ParseObject。我在Group对象中保存了一个任务的arraylist,然后检索了Group和Tasks。但是,每当我使用group.getList(" tasks")时,我都会在标题中看到错误,即使我确实没有将任务保存为JSONObject。我已经查看了stackoverflow,但我似乎无法找到其他人遇到此问题。
我还有另一个名为Message的ParseObject,我以完全相同的方式访问,而且我没有收到此错误。
sampleclass.class.php
这是我检索我的小组的地方
@ParseClassName("Task")
public class Task extends ParseObject {
public Task getTask(String objectId) {
return (Task) getParseObject(objectId);
}
public String getDescription() {
return getString("description");
}
public String getLocation() {
return getString("location");
}
public String getDate() {
return getString("date");
}
public String getTime() {
return getString("time");
}
}
在这里,我尝试检索任务列表。将Object更改为Task只会将错误位置移动到getList行。
ParseQuery<Group> query = ParseQuery.getQuery("Group");
query.include("messages");
query.include("tasks");
query.whereEqualTo("name", groupName);
query.getFirstInBackground...
这就是我将任务保存到Group对象的方法
ArrayList<Task> tasks = new ArrayList<>();
List<Object> list = this.getList("tasks");
tasks.clear();
for (Object obj : list) {
tasks.add((Task) obj); // here is the error spot
}
return tasks;
答案 0 :(得分:0)
I had a similar issue where after getting the list of custom ParseObjects that I stored in a field from my ParseUser, upon trying to access one of the objects, I got a ClassCastException. I investigated further by putting a breakpoint right at the line on which it was crashing, and upon looking at the debugger screen, I noticed that the list of objects that I had retrieved from my ParseUser was actually a list of nulls.
I think the issue might be that the object itself is null and for some reason, when a ParseObject is null, it seems to resolve itself to be a JSONObject rather than a proper ParseObject. I would check your Parse dashboard and make sure that this object is not null.
Also, if your list has pointers to the Task object, make sure that those pointers actually point to Tasks that actually still exist in your database, since it is possible that you have outdated pointers to ghost objects in your list.