NSInvalidArgumentException', reas-[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[4]'

ios, null, objective-c

Solution

The error means you are trying to put `nil` in the dictionary (which is not allowed). Since you are building the dictionaries with string literals those can't be `nil`. This means the problem is with one or more of your images.

Try this to help find the problem:

+(NSArray *)users
{
    UIImage *image1 = [UIImage imageNamed:@"person1.jpeg"];
    UIImage *image2 = [UIImage imageNamed:@"person2.jpeg"];
    UIImage *image3 = [UIImage imageNamed:@"person3.jpeg"];
    UIImage *image4 = [UIImage imageNamed:@"person4.jpeg"];

    NSDictionary *user1 = @{@"username" : @"master photographer", @"email" : @"worldtravel@me.com", @"password" : @"drowssap", @"age" : @24, @"profilePicture" : image1 };
    NSDictionary *user2 = @{@"username" : @"Lots of tots", @"email" : @"otterskips@me.com", @"password" : @"icecreamrocks", @"age" : @65, @"profilePicture" : image2 };
    NSDictionary *user3 = @{@"username" : @"iTechie", @"email" : @"theRealApple@me.com", @"password" : @"infiniteloop", @"age" : @30, @"profilePicture" : image3 };
    NSDictionary *user4 = @{@"username" : @"Royal", @"email" : @"king@me.com", @"password" : @"IGotAPalace", @"age" : @0, @"profilePicture" : image4 };

    NSArray *userArray = @[user1, user2, user3, user4];
    return userArray;
}

Now you can either use the debugger and see if `image1`, `image2`, `image3`, or `image4` is `nil` or add `NSLog` statements for each.

Keep in mind that filenames are case sensitive so be sure the name you pass to `imageNamed:` exactly matches the real filename. Also verify the images have the extension `jpeg` and not `jpg`. Make sure the images are being packaged in your resource bundle.

Problem

i got error NSInvalidArgumentException this is my model class ``` +(NSArray *)users { NSDictionary *user1 = @{@"username" : @"master photographer", @"email" : @"worldtravel@me.com", @"password" : @"drowssap", @"age" : @24, @"profilePicture" : [UIImage imageNamed:@"person1.jpeg"]}; NSDictionary *user2 = @{@"username" : @"Lots of tots", @"email" : @"otterskips@me.com", @"password" : @"icecreamrocks", @"age" : @65, @"profilePicture" : [UIImage imageNamed:@"person2.jpeg"]}; NSDictionary *user3 = @{@"username" : @"iTechie", @"email" : @"theRealApple@me.com", @"password" : @"infiniteloop", @"age" : @30, @"profilePicture" : [UIImage imageNamed:@"person3.jpeg"]}; NSDictionary *user4 = @{@"username" : @"Royal", @"email" : @"king@me.com", @"password" : @"IGotAPalace", @"age" : @0, @"profilePicture" : [UIImage imageNamed:@"person4.jpeg"]}; NSArray *userArray = @[user1, user2, user3, user4]; return userArray; } @end ``` and this is my viewdidload ``` self.users = [DMZUserData users]; NSLog(@"%@", self.users); ```

Original source