Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios NSInvalidArgumentException';,reas-[\uu NSPlaceholderDictionary initWithObjects:forKeys:count:]:尝试从对象[4]插入nil对象&x27;_Ios_Objective C_Null - Fatal编程技术网

Ios NSInvalidArgumentException';,reas-[\uu NSPlaceholderDictionary initWithObjects:forKeys:count:]:尝试从对象[4]插入nil对象&x27;

Ios NSInvalidArgumentException';,reas-[\uu NSPlaceholderDictionary initWithObjects:forKeys:count:]:尝试从对象[4]插入nil对象&x27;,ios,objective-c,null,Ios,Objective C,Null,我得到错误NSInvalidArgumentException这是我的模型类 +(NSArray *)users { NSDictionary *user1 = @{@"username" : @"master photographer", @"email" : @"worldtravel@me.com", @"password" : @"drowssap", @"age" : @24, @"profilePicture" : [UIImage imageNamed:@"person1.

我得到错误NSInvalidArgumentException这是我的模型类

+(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
这是我的观点

self.users = [DMZUserData users];
NSLog(@"%@", self.users);

这意味着你试图在字典中输入的一个值是nil,很可能是其中的一幅图片。您可以尝试将图像分配给变量,并检查它们是否存在这种情况。

该错误意味着您试图将
nil
放入字典(这是不允许的)。由于您正在使用字符串文本构建词典,因此这些文本不能是
nil
。这意味着问题出在一个或多个图像上

请尝试以下操作以帮助查找问题:

+(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;
}
现在,您可以使用调试器查看
image1
image2
image3
、或者
image4
是否为
nil
,或者为每个项添加
NSLog
语句


请记住,文件名区分大小写,因此请确保传递给
imageNamed:
的名称与实际文件名完全匹配。还要验证图像是否具有扩展名
jpeg
,而不是
jpg
。确保图像已打包到您的资源包中。

您尝试创建的其中一个UIImages为零。 请添加以下代码作为方法+(NSArray*)用户的第一行

这段代码将在控制台上打印不存在的图像。 请运行DEBUG,让我们看看断言的结果是什么


希望这有帮助

更好的治疗方法可能是将“NSDictionary”制作成这样:

NSDictionary *user1 = [NSDictionary dictionaryWithObjectsAndKeys: my obj & key here, nil];
尝试从对象[4]插入nil对象”“表示索引[4]处的键或值为nil


因此,正如其他人所说,这将是您的一个图像,因为索引[4]处的键是字符串文字。

您的一个(或多个)图像不存在,导致
nil
。我认为错误消息会告诉您出了什么问题。字典值列表中任何可能是
nil
的值都是
nil
。进行一些调试,然后自己找到。你有什么问题吗?@maddy我左侧的xcode中有一个图像文件。@trojanfoe抱歉,兄弟,但不幸的是,我目前正在学习objective c,所以我非常不懂。。我只是想请你帮我修复这个错误,我花了半天多的时间来处理这个错误:(还值得注意的是,如果使用了Xcode资产目录,扩展应该被省略。因为图像是jpeg格式的,这可能不是事实,但仍然应该提一提。这是一个更好的解决方法吗?仅仅因为这个方法:+(id)dictionaryWithObjectsAndKeys:(id)firstObject,…返回nil key的异常…istead:-(id)initWithDictionary:(NSDictionary*)dictionary copyItems:(BOOL)标志(我认为此方法在这里的示例中被调用)…似乎不返回关于nil key的任何内容
NSDictionary *user1 = [NSDictionary dictionaryWithObjectsAndKeys: my obj & key here, nil];