我在创建记录并将其发送给Parse时遇到以下异常,我想知道是否有人可以阐明它,或者如何寻找解决方案。
2014-04-23 22:38:19.397 DreamCatching[10731:303] Can't use nil for keys or values on PFObject. Use NSNull for values.
2014-04-23 22:38:19.399 DreamCatching[10731:303] (
0 CoreFoundation 0x00007fff8933a25c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff89827e75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8933a10c +[NSException raise:format:] + 204
3 ParseOSX 0x00000001000cc9ac -[PFObject setObject:forKey:] + 69
4 DreamCatching 0x000000010000681f -[DreamViewController endPlaces:] + 975
5 AppKit 0x00007fff8dfbd260 -[NSApplication sendAction:to:from:] + 327
6 AppKit 0x00007fff8dfbd0de -[NSControl sendAction:to:] + 86
7 AppKit 0x00007fff8e009c4d -[NSCell _sendActionFrom:] + 128
8 AppKit 0x00007fff8e023655 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2316
9 AppKit 0x00007fff8e022a27 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 487
10 AppKit 0x00007fff8e02213d -[NSControl mouseDown:] + 706
11 AppKit 0x00007fff8dfa3a58 -[NSWindow sendEvent:] + 11296
12 AppKit 0x00007fff8df425d4 -[NSApplication sendEvent:] + 2021
13 AppKit 0x00007fff8dd92a19 -[NSApplication run] + 646
14 AppKit 0x00007fff8dd7d7a3 NSApplicationMain + 940
15 DreamCatching 0x000000010001a862 main + 34
16 libdyld.dylib 0x00007fff886a45fd start + 1
17 ??? 0x0000000000000003 0x0 + 3
)
我发送的记录看起来像这样(在崩溃之前记录):
2014-04-23 22:38:19.397 DreamCatching[10731:303] endPlaces: newJoin: <DDPlaceJoin:new:(null)> {
ACL = "<PFACL: 0x6100002574f0>";
mainKey = 070213681717;
mainName = "About Time";
parseUser = "<PFUser:BJdxGyXnkn>";
placeKey = 042314094048;
placeName = London;
}
解析对象中没有其他用户元素。这也只是偶尔发生,尽管很频繁。
我的代码如下:
- (IBAction)endPlaces:(id)sender {
NSLog(@"%s", __FUNCTION__);
//selectedPlaces should be in its final state.
//use it to rebuild the placesJoin class
[self endSheet:self.sheet returnCode:result];
//rebuild Places Join array and save it. The replacement info is in selectedPlaces
//1. empty the current join array for this dream
[self clearPlaceJoins];
[PFQuery clearAllCachedResults];
// 2. Build new join table based on selectedPlaces
//NSLog(@"There are some Places noted in this dream");
NSLog(@"endPlaces: selectedPlaces is %@", selectedPlaces);
NSLog(@"endPlaces: selectedPlaces Count is %lu", (unsigned long)selectedPlaces.count);
for (int i=0; i < selectedPlaces.count; i++) {
PFObject *newJoin = [PFObject objectWithClassName:@"DDPlaceJoin"];
NSString *tempDreamKey = [selectedPlaces[i] valueForKey:@"mainKey"];
NSString *tempPlaceKey = [selectedPlaces[i] valueForKey:@"placeKey"];
NSString *tempDreamName = [selectedPlaces[i] valueForKey:@"mainName"];
NSString *tempPlaceName = [selectedPlaces[i] valueForKey:@"placeName"];
[newJoin setObject:tempDreamKey forKey:@"mainKey"];
[newJoin setObject:tempPlaceKey forKey:@"placeKey"];
[newJoin setObject:tempDreamName forKey:@"mainName"];
[newJoin setObject:tempPlaceName forKey:@"placeName"];
[newJoin setObject:[PFUser currentUser] forKey:@"parseUser"];
query.cachePolicy = kPFCachePolicyNetworkElseCache;
//Set ACL permissions for added security
PFACL *joinACL = [PFACL ACLWithUser:[PFUser currentUser]];
[newJoin setACL:joinACL];
NSLog(@"endPlaces: newJoin: %@", newJoin);
[newJoin saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
// Revert state on save error.
NSLog(@"Error saving a placejoin");
}
}];
}
}
谢谢你的帮助。
最佳答案
崩溃发生在对setObject:forKey:
的调用之一中,这意味着崩溃后您的NSLog。您可能会看到最后一个有效的记录,而不是导致问题的记录。
尝试在第一个setObject:forKey:
之前放置一个断点或NSLog,并确保所有temp*
值都不为零。如果有的是零,而从不该为零,那么您可能想找出原因。否则,您应该确保将这些值添加到[NSNull null]
之前注意这些值并将其更改为PFObject
。
关于ios - 向Parse.com类添加对象时发生异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23253864/