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
J Kim
15,218 PointsApp crashes when running [query whereKey:@"recipientIds" equalTo:[[PFUser currentUser] objectId]]; when not logged in.
(InboxTableViewController.m)
My immediate solution was to do the following:
if ([PFUser currentUser]) { PFQuery *query = [PFQuery queryWithClassName:@"Messages"]; [query whereKey:@"recipientIds" equalTo:[[PFUser currentUser] objectId]]; ...
On (void)viewDidLoad the view performs segue to login screen when currentUser is not available, but seems to appear that this does not take place before (void)viewWillAppear.
I am not sure if my set up is faulty, but I thought I'd mention it just in case it is a bug.
Following is the log for recreated crash:
2015-08-04 19:14:58.889 SnapchatClone[58289:3118808] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot do a comparison query for type: (null)' *** First throw call stack: ( 0 CoreFoundation 0x00000001113e7a75 exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000111080bb7 objc_exception_throw + 45 2 CoreFoundation 0x00000001113e79ad +[NSException raise:format:] + 205 3 SnapchatClone 0x000000010f87ea93 PFQueryAssertValidEqualityClauseClass + 345 4 SnapchatClone 0x000000010f87e8e4 -[PFQuery whereKey:equalTo:] + 76 5 SnapchatClone 0x000000010f836c93 -[InboxTableViewController viewWillAppear:] + 227 6 UIKit 0x0000000111a52311 -[UIViewController _setViewAppearState:isAnimating:] + 487 7 UIKit 0x0000000111a7d4e0 -[UINavigationController _startTransition:fromViewController:toViewController:] + 776 8 UIKit 0x0000000111a7e007 -[UINavigationController _startDeferredTransitionIfNeeded:] + 523 9 UIKit 0x0000000111a7eac7 -[UINavigationController __viewWillLayoutSubviews] + 43 10 UIKit 0x0000000111bc4d79 -[UILayoutContainerView layoutSubviews] + 202 11 UIKit 0x00000001119a21c3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521 12 QuartzCore 0x000000010ffc2c58 -[CALayer layoutSublayers] + 150 13 QuartzCore 0x000000010ffb787e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380 14 QuartzCore 0x000000010ffb76ee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 15 QuartzCore 0x000000010ff2536e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242 16 QuartzCore 0x000000010ff26482 _ZN2CA11Transaction6commitEv + 390 17 UIKit 0x000000011192668d -[UIApplication _reportMainSceneUpdateFinished:] + 44 18 UIKit 0x0000000111927375 -[UIApplication _runWithMainScene:transitionContext:completion:] + 2684 19 UIKit 0x0000000111925d35 -[UIApplication workspaceDidEndTransaction:] + 179 20 FrontBoardServices 0x0000000119190243 __31-[FBSSerialQueue performAsync:]_block_invoke + 16 21 CoreFoundation 0x000000011131cc7c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 12 22 CoreFoundation 0x00000001113129c5 __CFRunLoopDoBlocks + 341 23 CoreFoundation 0x0000000111312785 __CFRunLoopRun + 2389 24 CoreFoundation 0x0000000111311bc6 CFRunLoopRunSpecific + 470 25 UIKit 0x00000001119257a2 -[UIApplication _run] + 413 26 UIKit 0x0000000111928580 UIApplicationMain + 1282 27 SnapchatClone 0x000000010f8393c3 main + 115 28 libdyld.dylib 0x000000011627b145 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
2 Answers
Anthony Martinez
13,111 PointsHey JKim, the exact same thing happened to me yesterday (August 4th 2015). Turns out the problem may be associated with the Parse SDK itself. I commented out the line:
[query whereKey:@"recipientIds" equalTo:[[PFUser currentUser] objectId]];
ran the program and was able to engage with InboxViewController. If this works for you, let me know. Otherwise, keep trying.
Crashlytics report for the curious: http://crashes.to/s/6c6e9bd4be2
J Kim
15,218 PointsAnthony, I figured out that the problem is occurring because when you are not logged in [PFUser currentUser] will return null and that causes problem while querying.
Putting if ([PFUser currentUser]) { } around the entire query should fixed the problem since it prevents the query when there is no logged in user present.
Commenting out the line will not be a solution since you still need that query when you are logged in.