我试图从包含cols的表中检索行:
ACL
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("PartiesInvites");
ArrayList<ParseObject> partiesId = new ArrayList<>();
for (int i = 0; i < mParties.size(); i++) {
partiesId.add(mParties.get(i).getObjectId());
Log.d("UU-UPIL", "partyId = " + partiesId.get(i));
}
query.whereContainsAll("PartyId", partiesId);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> partiesInvitationsIn, ParseException e) {
Log.d("UU-UPIL", "finding parties invitations");
if (e == null) {
for (int i = 0; i < partiesInvitationsIn.size(); i++) {
Log.v("UU-UPIL", partiesInvitationsIn.get(i).getObjectId());
}
mPartiesInvitations = partiesInvitationsIn;
Log.d("UU-UPIL", String.valueOf(partiesInvitationsIn.size()));
} else {
e.printStackTrace();
}
}
});
这是我得到的例外
02-11 13:06:03.907 28398-28398/com.whoCare.noOne W/System.err﹕ com.parse.ParseException: java.lang.IllegalStateException: A ParseObject subclass default constructor must not make changes to the object that cause it to be dirty.
02-11 13:06:03.907 28398-28398/com.whoCare.noOne W/System.err﹕ at com.parse.Parse$6$1.run(Parse.java:971)
02-11 13:06:03.907 28398-28398/com.whoCare.noOne W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:733)
02-11 13:06:03.907 28398-28398/com.whoCare.noOne W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
02-11 13:06:03.907 28398-28398/com.whoCare.noOne W/System.err﹕ at android.os.Looper.loop(Looper.java:212)
02-11 13:06:03.907 28398-28398/com.whoCare.noOne W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5135)
02-11 13:06:03.907 28398-28398/com.whoCare.noOne W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
02-11 13:06:03.907 28398-28398/com.whoCare.noOne W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:515)
02-11 13:06:03.907 28398-28398/com.whoCare.noOne W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877)
02-11 13:06:03.907 28398-28398/com.whoCare.noOne W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
02-11 13:06:03.907 28398-28398/com.whoCare.noOne W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
02-11 13:06:03.907 28398-28398/com.whoCare.noOne W/System.err﹕ Caused by: java.lang.IllegalStateException: A ParseObject subclass default constructor must not make changes to the object that cause it to be dirty.
02-11 13:06:03.917 28398-28398/com.whoCare.noOne W/System.err﹕ at com.parse.ParseObject.createWithoutData(ParseObject.java:257)
02-11 13:06:03.917 28398-28398/com.whoCare.noOne W/System.err﹕ at com.parse.ParseObject.fromJSON(ParseObject.java:524)
02-11 13:06:03.917 28398-28398/com.whoCare.noOne W/System.err﹕ at com.parse.ParseObject.fromJSON(ParseObject.java:499)
02-11 13:06:03.917 28398-28398/com.whoCare.noOne W/System.err﹕ at com.parse.ParseQuery.convertFindResponse(ParseQuery.java:386)
02-11 13:06:03.917 28398-28398/com.whoCare.noOne W/System.err﹕ at com.parse.ParseQuery.access$600(ParseQuery.java:80)
02-11 13:06:03.917 28398-28398/com.whoCare.noOne W/System.err﹕ at com.parse.ParseQuery$6.then(ParseQuery.java:567)
02-11 13:06:03.917 28398-28398/com.whoCare.noOne W/System.err﹕ at com.parse.ParseQuery$6.then(ParseQuery.java:558)
02-11 13:06:03.917 28398-28398/com.whoCare.noOne W/System.err﹕ at bolts.Task$9.run(Task.java:444)
02-11 13:06:03.917 28398-28398/com.whoCare.noOne W/System.err﹕ at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:97)
我尝试更改&#34; whereContainsAll&#34; to&#34; whereContainedIn&#34;但我一直得到同样的例外。我的代码有什么问题!?
答案 0 :(得分:2)
ParseObject子类的默认构造函数不能对导致它变脏的对象进行更改。
我不确定你的代码中是否有某个parseObject的子类用于放入数据库条目,但是在修改该子类的构造函数中的项时会引发此异常
确保您的子类具有公共默认值(即零参数)构造函数。您不得修改此构造函数中的任何ParseObject字段。
答案 1 :(得分:0)
更改此
query.whereContainsAll("PartyId", partiesId);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> partiesInvitationsIn, ParseException e) {
Log.d("UU-UPIL", "finding parties invitations");
if (e == null) {
for (int i = 0; i < partiesInvitationsIn.size(); i++) {
Log.v("UU-UPIL", partiesInvitationsIn.get(i).getObjectId());
}
mPartiesInvitations = partiesInvitationsIn;
Log.d("UU-UPIL", String.valueOf(partiesInvitationsIn.size()));
} else {
e.printStackTrace();
}
}
});
到此
query.whereContainsAll("PartyId", partiesId);
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> partiesInvitationsIn, ParseException e) {
Log.d("UU-UPIL", "finding parties invitations");
if (e == null) {
for (int i = 0; i < partiesInvitationsIn.size(); i++) {
Log.v("UU-UPIL", partiesInvitationsIn.get(i).getObjectId());
}
mPartiesInvitations = partiesInvitationsIn;
Log.d("UU-UPIL", String.valueOf(partiesInvitationsIn.size()));
} else {
e.printStackTrace();
}
}
});
基本上只需在完成方法之前添加 @Override