0

我想将一个新的ParseObject用于在 Parse 上存储数据)保存到服务器。这是我的代码:

private List<String> groupFreindsName = new ArrayList<String>();
if (groupFreindsName.size() > 0) {
    Log.d("group", "query success");
    final ParseObject saleObj = new ParseObject("all");
    saleObj.put("type", "g");
    saleObj.addAll("groupFreindsName", groupFreindsName);
    saleObj.put("ppp", "ppp");
    saleObj.saveInBackground();
}

但是它不会将其保存到服务器;当我调试它时,我看到它进入了这个方法并进入了这个saveInBackground()方法。但是,我在服务器上看不到该对象。

如果我删除该行:

    saleObj.addAll("groupFreindsName", groupFreindsName);

它成功上传了对象。

此外,在这两次groupFreindsName列表中都不是空的并且包含字符串,并且在这两次我都没有遇到异常。

这是日志猫:

04-03 20:32:27.723: D/dalvikvm(1249): GC_FOR_ALLOC freed 1624K, 12% free 28407K/32036K, paused 118ms, total 131ms
04-03 20:32:29.153: I/Choreographer(1249): Skipped 267 frames!  The application may be doing too much work on its main thread.
04-03 20:32:30.693: I/Choreographer(1249): Skipped 36 frames!  The application may be doing too much work on its main thread.
04-03 20:32:32.893: D/InputEventConsistencyVerifier(1249): KeyEvent: ACTION_UP but key was not down.
04-03 20:32:32.893: D/InputEventConsistencyVerifier(1249):   in android.widget.EditText{4121a9a0 VFED..CL .F....I. 0,493-425,538 #7f0800a5 app:id/descriptionTextGroup}
04-03 20:32:32.893: D/InputEventConsistencyVerifier(1249):   0: sent at 973006000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_G, scanCode=34, metaState=0, flags=0x8, repeatCount=0, eventTime=973006, downTime=972697, deviceId=0, source=0x101 }
04-03 20:32:32.893: D/InputEventConsistencyVerifier(1249):   -- recent events --
04-03 20:32:32.893: D/InputEventConsistencyVerifier(1249):   1: sent at 972697535000, MotionEvent { action=ACTION_UP, id[0]=0, x[0]=139.0, y[0]=26.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=972697, downTime=972661, deviceId=0, source=0x1002 }
04-03 20:32:32.893: D/InputEventConsistencyVerifier(1249):   2: sent at 972661805000, MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=139.0, y[0]=26.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=972661, downTime=972661, deviceId=0, source=0x1002 }
04-03 20:32:35.394: I/Choreographer(1249): Skipped 40 frames!  The application may be doing too much work on its main thread.
04-03 20:32:35.633: I/Choreographer(1249): Skipped 33 frames!  The application may be doing too much work on its main thread.
04-03 20:32:36.663: I/Choreographer(1249): Skipped 67 frames!  The application may be doing too much work on its main thread.
04-03 20:32:36.823: D/dalvikvm(1249): GC_CONCURRENT freed 856K, 8% free 29608K/32036K, paused 105ms+95ms, total 366ms
04-03 20:32:39.274: D/dalvikvm(1249): GC_CONCURRENT freed 1433K, 6% free 30153K/32036K, paused 121ms+137ms, total 377ms
04-03 20:32:39.683: I/Choreographer(1249): Skipped 34 frames!  The application may be doing too much work on its main thread.
04-03 20:32:40.384: I/Choreographer(1249): Skipped 41 frames!  The application may be doing too much work on its main thread.
04-03 20:32:40.844: I/Choreographer(1249): Skipped 113 frames!  The application may be doing too much work on its main thread.
04-03 20:32:41.154: I/Choreographer(1249): Skipped 73 frames!  The application may be doing too much work on its main thread.
04-03 20:32:43.193: D/group(1249): query success
04-03 20:32:46.683: I/Choreographer(1249): Skipped 49 frames!  The application may be doing too much work on its main thread.
04-03 20:32:48.593: D/dalvikvm(1249): GC_FOR_ALLOC freed 1725K, 6% free 30261K/32144K, paused 111ms, total 130ms
04-03 20:32:48.593: I/dalvikvm-heap(1249): Grow heap (frag case) to 30.103MB for 456992-byte allocation
04-03 20:32:48.723: D/dalvikvm(1249): GC_FOR_ALLOC freed 1086K, 10% free 29621K/32592K, paused 98ms, total 98ms
04-03 20:32:50.233: D/onScroll(1249): enter onScroll3

这是一个更新的 logcat:

04-04 07:11:00.231: W/System.err(1158): com.parse.ParseException: can't add objects for a field that isn't an array
04-04 07:11:00.281: W/System.err(1158):     at com.parse.ParseCommand$3.then(ParseCommand.java:340)
04-04 07:11:00.297: W/System.err(1158):     at com.parse.Task$10.run(Task.java:442)
04-04 07:11:00.297: W/System.err(1158):     at com.parse.Task$1.execute(Task.java:67)
04-04 07:11:00.301: W/System.err(1158):     at com.parse.Task.completeImmediately(Task.java:439)
04-04 07:11:00.301: W/System.err(1158):     at com.parse.Task.continueWith(Task.java:316)
04-04 07:11:00.301: W/System.err(1158):     at com.parse.Task.continueWith(Task.java:327)
04-04 07:11:00.301: W/System.err(1158):     at com.parse.Task$8.then(Task.java:377)
04-04 07:11:00.301: W/System.err(1158):     at com.parse.Task$8.then(Task.java:1)
04-04 07:11:00.301: W/System.err(1158):     at com.parse.Task$11.run(Task.java:474)
04-04 07:11:00.301: W/System.err(1158):     at com.parse.Task$1.execute(Task.java:67)
04-04 07:11:00.311: W/System.err(1158):     at com.parse.Task.completeAfterTask(Task.java:471)
04-04 07:11:00.321: W/System.err(1158):     at com.parse.Task.access$9(Task.java:467)
04-04 07:11:00.321: W/System.err(1158):     at com.parse.Task$7.then(Task.java:343)
04-04 07:11:00.321: W/System.err(1158):     at com.parse.Task$7.then(Task.java:1)
04-04 07:11:00.336: W/System.err(1158):     at com.parse.Task.runContinuations(Task.java:502)
04-04 07:11:00.341: W/System.err(1158):     at com.parse.Task.access$5(Task.java:498)
04-04 07:11:00.341: W/System.err(1158):     at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:557)
04-04 07:11:00.341: W/System.err(1158):     at com.parse.Task$TaskCompletionSource.setResult(Task.java:591)
04-04 07:11:00.341: W/System.err(1158):     at com.parse.Task$11$1.then(Task.java:485)
04-04 07:11:00.341: W/System.err(1158):     at com.parse.Task$11$1.then(Task.java:1)
04-04 07:11:00.341: W/System.err(1158):     at com.parse.Task$10.run(Task.java:442)
04-04 07:11:00.341: W/System.err(1158):     at com.parse.Task$1.execute(Task.java:67)
04-04 07:11:00.341: W/System.err(1158):     at com.parse.Task.completeImmediately(Task.java:439)
04-04 07:11:00.351: W/System.err(1158):     at com.parse.Task.access$8(Task.java:435)
04-04 07:11:00.351: W/System.err(1158):     at com.parse.Task$6.then(Task.java:309)
04-04 07:11:00.351: W/System.err(1158):     at com.parse.Task$6.then(Task.java:1)
04-04 07:11:00.361: W/System.err(1158):     at com.parse.Task.runContinuations(Task.java:502)
04-04 07:11:00.361: W/System.err(1158):     at com.parse.Task.access$5(Task.java:498)
04-04 07:11:00.361: W/System.err(1158):     at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:557)
04-04 07:11:00.361: W/System.err(1158):     at com.parse.Task$TaskCompletionSource.setResult(Task.java:591)
04-04 07:11:00.361: W/System.err(1158):     at com.parse.Task$11$1.then(Task.java:485)
04-04 07:11:00.361: W/System.err(1158):     at com.parse.Task$11$1.then(Task.java:1)
04-04 07:11:00.361: W/System.err(1158):     at com.parse.Task$10.run(Task.java:442)
04-04 07:11:00.371: W/System.err(1158):     at com.parse.Task$1.execute(Task.java:67)
04-04 07:11:00.371: W/System.err(1158):     at com.parse.Task.completeImmediately(Task.java:439)
04-04 07:11:00.371: W/System.err(1158):     at com.parse.Task.continueWith(Task.java:316)
04-04 07:11:00.371: W/System.err(1158):     at com.parse.Task.continueWith(Task.java:327)
04-04 07:11:00.371: W/System.err(1158):     at com.parse.Task$11.run(Task.java:478)
04-04 07:11:00.371: W/System.err(1158):     at com.parse.Task$1.execute(Task.java:67)
04-04 07:11:00.371: W/System.err(1158):     at com.parse.Task.completeAfterTask(Task.java:471)
04-04 07:11:00.381: W/System.err(1158):     at com.parse.Task.access$9(Task.java:467)
04-04 07:11:00.381: W/System.err(1158):     at com.parse.Task$7.then(Task.java:343)
04-04 07:11:00.381: W/System.err(1158):     at com.parse.Task$7.then(Task.java:1)
04-04 07:11:00.381: W/System.err(1158):     at com.parse.Task.runContinuations(Task.java:502)
04-04 07:11:00.381: W/System.err(1158):     at com.parse.Task.access$5(Task.java:498)
04-04 07:11:00.381: W/System.err(1158):     at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:557)
04-04 07:11:00.381: W/System.err(1158):     at com.parse.Task$TaskCompletionSource.setResult(Task.java:591)
04-04 07:11:00.381: W/System.err(1158):     at com.parse.Task$3.run(Task.java:225)
04-04 07:11:00.381: W/System.err(1158):     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
04-04 07:11:00.381: W/System.err(1158):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-04 07:11:00.381: W/System.err(1158):     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153)
04-04 07:11:00.381: W/System.err(1158):     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)
04-04 07:11:00.391: W/System.err(1158):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-04 07:11:00.391: W/System.err(1158):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-04 07:11:00.391: W/System.err(1158):     at java.lang.Thread.run(Thread.java:856)
4

1 回答 1

0

您可以使用addUnique(将对象添加到与给定键关联的数组中,前提是它尚不存在于数组中。)

例如:

代替

 saleObj.addAll("groupFreindsName", groupFreindsName);

for(String value: groupFreindsName){
saleObj.addUnique("groupFreindsName", value);
}

或与

saleObj.add("groupFreindsName", groupFreindsName);
于 2013-04-03T20:05:37.113 回答