0

I'm getting the following exception while creating and sending a record to Parse, and I wonder if anyone could shed light on it, or how to look for solutions..

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
)

The record I'm sending looks like this (logged just before the crash):

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;
}

There are no other user elements in the Parse object. This is also only happening on occasion, albeit frequently.

My code is as follows:

- (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");
            }
        }];

    }

}

Thanks for any help.

2 Answers 2

1

The crash is occurring in one of the calls to setObject:forKey:, which means your NSLog is AFTER the crash. You're probably seeing the last record that worked rather than the one that's causing the problem.

Try putting a breakpoint or NSLog before the first setObject:forKey: and makes sure all the temp* values are non-nil. If any are nil and they're never supposed to be, you may want to figure out why. Otherwise, you should just make sure to watch for those values and change them to [NSNull null] before adding them to your PFObject.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks to you both. adPalumbo was correct that there was a null item. CrimsonChris gave me a solution that allows me to test which item was in fact, null (It was the placeName). +1 to each of you. I wish I could mark both answers as correct, and I appreciate the help!! (I'm gonna toss a coin)..
1

The error message is pretty descriptive, one of the objects set on newJoin is nil. Perhaps it is [PFUser currentUser].

You could handle it like this for each call to setObject...

[newJoin setObject:tempDreamKey ?: [NSNull null] forKey:@"mainKey"];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.