Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Ribbit app crash

The Ribbit app crashed when I clicked the send button in the Camera View Controller. The output said

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't use nil for keys or values on PFObject. User NSNull for values.'

- (IBAction)send:(id)sender {
    if (self.image == nil && [self.videoFilePath length] == 0) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Try again" message:@"Please capture or select a video or photo to share" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

        [alertView show];
        [self presentViewController:self.imagePicker animated:NO completion:nil];


      }
    else {
        [self uploadMessage];
        [self reset];

        [self.tabBarController setSelectedIndex:0];
    }

2 Answers

Sebastian Vargas Macedo
Sebastian Vargas Macedo
6,375 Points

Hi,

I think that the problem is the [self reset] function. You should call it inside the uploadMessage function, after you have successfully saved the message object to the server.

If you call it outside uploadMessage, the reset function will have deleted some data before the asynchronous task is completed. That's the reason of the 'nil for keys' thing in the error message.

Hope this helps ;)

Thanks for the help! I am new to Objective-C so I don't quite understand what you mean. It would be great if you could write that line of code for me.Thanks! Sebastian Vargas Macedo

Neil Shweky
Neil Shweky
5,022 Points

The only thing I could think of to do is change from

completion: nil];

to

completion:NULL];

See if that works, if not, set breakpoints around that area to see exactly where the problem is happening.

P.S. And by the way, my best bet is that the problem is happening in the uploadMessage method....