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

Tamara J
Tamara J
189 Points

Trying to Build the Ribbit app in iOS 8: Terminating with Uncaught Exception : NSException

Hi everyone, trying to build the Ribbit app with the new iOS, but it keeps failing at login. Here's the code.

       (IBAction)login:(id)sender {
      NSString *username = [self.enterUsername.text stringByTrimmingCharactersInSet:         
    [NSCharacterSet whitespaceAndNewlineCharacterSet]];
     NSString *password = [self.enterPassword.text stringByTrimmingCharactersInSet:  
    [NSCharacterSet whitespaceAndNewlineCharacterSet]];

if ([username length] == 0 || [password length] == 0) {
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops!"
                                                        message:@"Please enter a username, password."
                                                       delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
    return;
     }else {

    [PFUser logInWithUsernameInBackground:username password:password block:^(PFUser *user, 
     NSError
                                                                             *error) {
        if (error) {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry!"
                                                                message:[error.userInfo
                                                                         objectForKey:@"error"]
                                                               delegate:nil cancelButtonTitle:@"OK"
                                                      otherButtonTitles:nil];
            [alertView show];
        }
        else {
            [self.navigationController popToRootViewControllerAnimated:YES];
        }
    }];
   }


   }

The error message: 2014-10-21 11:40:17.047 Yes-No App[5401:605012] *** Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: 'Cannot do a comparison query for type: (null)'

Anyone know how to tweak it so it works for iOS 8

Edit:

I see others were having issues with it before...not sure how I can fix this as it's the same code from the application.

Second Edit: I have all the code...used your example Russell and it still threw an exception...breakpoint was different though.

Russell Warwick
Russell Warwick
1,601 Points

You have missed out what happens if the login is successful ?

show look like this <-(IBAction)logIn:(id)sender{ NSString *userName = [self.userNameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; NSString *password = [self.passwordField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

if ([userName length] ==0 || [password length]==0) {

UIAlertView * alertView =[[UIAlertView alloc]initWithTitle:@"Oops!" message:@"Please enter a username and password" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alertView show];

} else {

[PFUser logInWithUsernameInBackground:userName password:password block:^(PFUser *user, NSError *error) {
    if (user) {
        [self.navigationController popToRootViewControllerAnimated:YES];
    } else {

    }

}];

} }

Tamara J
Tamara J
189 Points

Hi Russell,

I actually had the code for when the login was successful, I just didn't copy and paste all of it. My mistake!

I used the code example you provided and it still failed, the Breakpoint was this: 0x148ca5: jmp 0x148cb8 ; +[PFInternalUtils assertValidClassForQuery:] + 394 at PFInternalUtils.m:413

Russell Warwick
Russell Warwick
1,601 Points

Fair enough works for me fine haha. Programing is frustrating... Also try disabling breakpoints ?

Tamara J
Tamara J
189 Points

How do I do that?

Russell Warwick
Russell Warwick
1,601 Points

Go to debug and then click on deactivate breakpoints. Sometimes it will still not work but most of the time it will unstick where your code is stuck on :)

Saw someone else with the same issue, so ill just parse the fix below. Hope it helps.

There is not a problem with iOS 8. You are attempting to query Parse with the users credentials, but you are not logged in.

Add this peace of code to your -viewDidLoad and it should solve your problem.

if([PFUser currentUser])
{
    [self updateMessages];
}
else
{
    [self performSegueWithIdentifier:@"showLogin" sender:self];
}

All it does is checks if there is a logged in user, if there is, it updates the messages(calls parse for results), otherwise send the user to the log in view.

TIP: Copy and paste the error code on google if you can decipher it, it will most likely have happened to someone else before.

2 Answers

Tamara J
Tamara J
189 Points

Yeah, someone on StackOverflow helped me fix it:

''' if ([userName length] ==0 || [Password length]==0) {

    UIAlertView * alertView =[[UIAlertView alloc]initWithTitle:@"Oops!" message:@"Please enter a username and password" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
    [alertView show];

} else {

    [PFUser logInWithUsernameInBackground:userName password:Password block:^(PFUser *user, NSError *error) {
        if (user) {
            [self.navigationController popToRootViewControllerAnimated:YES];
        }
    }];

} }

'''

Ethan Neff
Ethan Neff
27,058 Points

Any solution to this problem? My Ribbit stopped working with the same error in iOS 8 as well.

Tamara J
Tamara J
189 Points

See my answer above.

Ethan Neff
Ethan Neff
27,058 Points

Unfortunately, that solution did not work for me...

I am still unable to run the app even after implementing your code... http://i.imgur.com/fcw01ix.png

Tamara J
Tamara J
189 Points

Hey Ethan,

Are you running it with iPhone 6? The thing that solved my problem was running it in a different project (copying and pasting the code in a new one). I don't know what I did exactly, but I did try running it in the iPhone 5 simulator, and I think that helped a little. I'm not sure.

I hope this proves helpful to you.

Ethan Neff
Ethan Neff
27,058 Points

Tamara, is there anyway you could send me a copy of your project?

I just cannot get my Ribbit to work like it did before iOS 8.

Ethan Neff
Ethan Neff
27,058 Points

Figured out the solution to my problem... it can be found here: https://teamtreehouse.com/forum/ribbit-app-does-not-work-in-ios-8