NSInvalidArgumentException: App crashes upon opening

HalesEnchanted

I am trying to build an app where users can like and comment on posts, a lot like instagram. All the posts / likes / comments are saved on parse.com! I have been able to put together the code, which should work as it does on the sample app but when I move over the files, this code makes it crash:

 [query whereKey:@"user" containedIn:self.usersToDisplay];

The crash message being:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* setObjectForKey: object cannot be nil (key: $in)'**

The rest of the code goes something like this:

- (void)viewDidLoad
{
// self.usersToDisplay = @[[PFUser currentUser]];

self.parseClassName = @"Photo";
[super viewDidLoad];

self.tableView.layer.cornerRadius = 10;
self.tableView.layer.masksToBounds = YES;
}

- (void)setUsersToDisplay:(NSArray *)usersToDisplay {
_usersToDisplay = usersToDisplay;

if (self.isViewLoaded)
{
    [self loadObjects];
}
}


  - (PFQuery *)queryForTable {
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];

// If Pull To Refresh is enabled, query against the network by default.
if (self.pullToRefreshEnabled) {
    query.cachePolicy = kPFCachePolicyNetworkOnly;
}

 [query whereKey:@"user" containedIn:self.usersToDisplay];
[query addDescendingOrder:@"createdAt"];
return query;
}

 -(PFTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
  {
   PhotoViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"ImageCellReuseID"];
if(!cell)
{
    cell = [[PhotoViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"ImageCellReuseID"];
}

cell.imageView.file = object[@"image"];
[cell.imageView loadInBackground];

NSDateFormatter* formatter = [NSDateFormatter new];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateStyle:NSDateFormatterShortStyle];
NSString* uploaded = [formatter stringFromDate:object.createdAt];

cell.textLabel.text = [NSString stringWithFormat:@"Taken By %@ ", object[@"username"]];

cell.detailTextLabel.text = uploaded;

return cell;
}


  -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  [self performSegueWithIdentifier:@"ShowDetail" sender:indexPath];
 }

Any idea why it crashes?

Rob Norback

It looks like one of the values in your array self.usersToDisplay doesn't have a valid object for the query.

From the parse documentation:

If you want to retrieve objects matching several different values, you can use whereKey:containedIn:, providing an array of acceptable values. This is often useful to replace multiple queries with a single query. For example, if you want to retrieve scores made by any player in a particular list:

// Finds scores from any of Jonathan, Dario, or Shawn
// Using PFQuery
NSArray *names = @[@"Jonathan Walsh", @"Dario Wunsch", @"Shawn Simon"]; 
[query whereKey:@"playerName" containedIn:names];

Make sure all the values in your array match the values in your database.

Cheers!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

BluetoothChat app crashes upon onDestroy() in Android 4.4

From Dev

Android App crashes upon menu button click

From Dev

Run a method upon NSWindow opening?

From Dev

GPPSignIn crashes with NSInvalidArgumentException

From Dev

Facebook application Review failed - "Your app downloads successfully, but crashes upon opening"

From Dev

NSInvalidArgumentException when opening SKScene from UIViewController

From Dev

Azure Storage Explorer crashes upon opening a storage account

From Dev

App Crashes upon receiving data from intent

From Dev

app crashes when opening another activity in Navigation Drawer

From Dev

My app crashes when opening tablayout activity

From Dev

Android App crashes upon menu button click

From Dev

Android app crashes opening InputStream from an XML

From Dev

Facebook application Review failed - "Your app downloads successfully, but crashes upon opening"

From Dev

SpriteKit Terminating App due NSInvalidArgumentException

From Dev

Windows 8.1: PC crashes after opening metro app

From Dev

How do I stop mail.app and its nag screen from opening upon login in OS X if I don't use it

From Dev

Github App for Mac crashes upon opening

From Dev

App is all of the sudden throwing an NSInvalidArgumentException

From Dev

NSInvalidArgumentException: App crashes upon opening

From Dev

iPad App Crashes When Opening Share Sheet

From Dev

app crashes while opening new fragment inside viewpager

From Dev

App Crashes upon receiving data from intent

From Dev

UrbanAirship app crashes upon receipt of message

From Dev

App crashes upon launch

From Dev

Kile crashes upon closing project

From Dev

Qgis crashes upon starting

From Dev

Android app crashes upon removing an item from FirebaseRecyclerAdapter

From Dev

No controls showing upon opening form

From Dev

My App crashes upon creating Sqlite DB

Related Related

  1. 1

    BluetoothChat app crashes upon onDestroy() in Android 4.4

  2. 2

    Android App crashes upon menu button click

  3. 3

    Run a method upon NSWindow opening?

  4. 4

    GPPSignIn crashes with NSInvalidArgumentException

  5. 5

    Facebook application Review failed - "Your app downloads successfully, but crashes upon opening"

  6. 6

    NSInvalidArgumentException when opening SKScene from UIViewController

  7. 7

    Azure Storage Explorer crashes upon opening a storage account

  8. 8

    App Crashes upon receiving data from intent

  9. 9

    app crashes when opening another activity in Navigation Drawer

  10. 10

    My app crashes when opening tablayout activity

  11. 11

    Android App crashes upon menu button click

  12. 12

    Android app crashes opening InputStream from an XML

  13. 13

    Facebook application Review failed - "Your app downloads successfully, but crashes upon opening"

  14. 14

    SpriteKit Terminating App due NSInvalidArgumentException

  15. 15

    Windows 8.1: PC crashes after opening metro app

  16. 16

    How do I stop mail.app and its nag screen from opening upon login in OS X if I don't use it

  17. 17

    Github App for Mac crashes upon opening

  18. 18

    App is all of the sudden throwing an NSInvalidArgumentException

  19. 19

    NSInvalidArgumentException: App crashes upon opening

  20. 20

    iPad App Crashes When Opening Share Sheet

  21. 21

    app crashes while opening new fragment inside viewpager

  22. 22

    App Crashes upon receiving data from intent

  23. 23

    UrbanAirship app crashes upon receipt of message

  24. 24

    App crashes upon launch

  25. 25

    Kile crashes upon closing project

  26. 26

    Qgis crashes upon starting

  27. 27

    Android app crashes upon removing an item from FirebaseRecyclerAdapter

  28. 28

    No controls showing upon opening form

  29. 29

    My App crashes upon creating Sqlite DB

HotTag

Archive