[英]Exception while adding a an object to a Parse.com class
我在創建和發送記錄到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;
}
Parse對象中沒有其他用戶元素。 這也只是偶爾發生,盡管經常發生。
我的代碼如下:
- (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");
}
}];
}
}
謝謝你的幫助。
錯誤消息非常具有描述性, newJoin
上設置的對象newJoin
是nil。 也許它是[PFUser currentUser]
。
你可以像每次調用setObject一樣處理它...
[newJoin setObject:tempDreamKey ?: [NSNull null] forKey:@"mainKey"];
崩潰發生在對setObject:forKey:
一次調用中,這意味着你的NSLog在崩潰之后。 您可能看到最后一條記錄有效,而不是引起問題的記錄。
嘗試在第一個setObject:forKey:
之前放置一個斷點或NSLog setObject:forKey:
並確保所有的temp*
值都是非零的。 如果它們是零並且它們永遠不應該是,那么你可能想弄清楚原因。 否則,您應該確保在將它們添加到PFObject
之前監視這些值並將它們更改為[NSNull null]
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.