简体   繁体   English

setObject:ForKey:崩溃?

[英]setObject:ForKey: crash?

I am getting this crash in the console: 我在控制台中遇到了这个崩溃:

2011-08-27 23:26:45.041 App[1672:3117] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary setObject:forKey:]: attempt to insert nil key'
*** First throw call stack:
(0x3231c8c3 0x362ee1e5 0x3231c7bd 0x3231c7df 0x32289679 0x3052e865 0x3220fd55 0x3221b7a3 0x3345e4b7 0x3345e38c)
terminate called throwing an exception[Switching to process 10243 thread 0x2803]
[Switching to process 10243 thread 0x2803]

The only line that I think would fire at the time it crashes that relates to this crash is this line: 我认为在碰撞时与此崩溃相关的唯一一条线是这一行:

UIImage *photo = [self.selectedDictionary objectForKey:@"ProfileImage"];

Does anything look wrong here? 这里有什么不妥吗? What could be the problem? 可能是什么问题呢?

Edit1: It is crashing when I do this to call a method: Code: Edit1:当我这样做来调用方法时崩溃:代码:

if(actionSheet.tag == 1) {
            [self showAchievements];
        }

This is the showAchievements method: Code: 这是showAchievements方法:代码:

- (void)showAchievements {
    GKAchievementViewController *achievements = [[GKAchievementViewController alloc] init];
    if (achievements != nil)
    {
        achievements.achievementDelegate = self;
        [self presentModalViewController:achievements animated:YES];
    }
}

- (void)achievementViewControllerDidFinish:(GKAchievementViewController *)viewController
{
    [self dismissModalViewControllerAnimated:YES];
    [viewController release];
}

Can this crash be because I have not properly hooked everything up in iTC? 这次崩溃是因为我没有在iTC中正确地搞定所有事情吗? I am definitely sure it crashes in that method and I do not know why. 我肯定肯定它在那种方法中崩溃了,我不知道为什么。

Does anyone have any ideas? 有没有人有任何想法?

Edit2: I am getting down to it here, in my console, right before it crashes it has a line saying Missed Method. 编辑2:我正在这里,在我的控制台中,在它崩溃之前它有一条线说错过方法。 So I search for where this NSLog is and it is in GameCenterManager.m, a file necessary for Game Center I think. 所以我搜索这个NSLog的位置,它在GameCenterManager.m中,我认为这是Game Center所必需的文件。 Here is the method: 这是方法:

    - (void) callDelegate: (SEL) selector withArg: (id) arg error: (NSError*) err
{
    assert([NSThread isMainThread]);
    if([delegate respondsToSelector: selector])
    {
        if(arg != NULL)
        {
            [delegate performSelector: selector withObject: arg withObject: err];
        }
        else
        {
            [delegate performSelector: selector withObject: err];
        }
    }
    else
    {
        NSLog(@"Missed Method");
    }
}

So from that code do you see whats wrong? 那么从那段代码你看到什么错了?

Thanks! 谢谢!

I'd guess the answer is right there in the code you posted: 我猜你的答案就在答案中:

reason: '-[__NSCFDictionary setObject:forKey:]: attempt to insert nil key'

You can't insert a nil key into a dictionary. 您不能将nil键插入字典。 Are you doing something like [myDictionary setObject:foo forKey:bar] where 'bar' is nil? 你在做[myDictionary setObject:foo forKey:bar],其中'bar'是零吗?

Incidentally, you also can't insert nil values into a dictionary, but that doesn't appear to be what the error reason indicates. 顺便说一句,您也不能将nil值插入字典中,但这似乎不是错误原因所指示的。 You can call [myDictionary setValue:nil forKey:bar] (as long as bar isn't nil) - this removes the key from the dictionary. 可以调用[myDictionary setValue:nil forKey:bar] (只要bar不是nil) - 这会从字典中删除密钥。 And if you want to indicate a "nil" value, you can insert the NSNull object into a dictionary. 如果要指示“nil”值,可以将NSNull对象插入字典中。 But keys -- keys must always be non-nil. 但是键 - 键必须始终是非零的。

从日志中看起来,关键的profileImage等于nil ,这意味着NSDictionary中没有该键的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 __NSDictionaryI setObject:forKey:崩溃 - __NSDictionaryI setObject:forKey: Crash NSDictionaryM setObject:forKey:EXC_BAD_ACCESS崩溃 - NSDictionaryM setObject:forKey: EXC_BAD_ACCESS crash NSUserDefaults setObject:forKey死锁? - NSUserDefaults setObject:forKey deadlocks? 仅在iOS 9中,应用程序在[__NSCFDictionary setObject:forKey:]时崩溃 - App crashes at [__NSCFDictionary setObject:forKey:] in iOS 9 only setObject:forKey:和setValue:forKey:在NSMutableDictionary中的区别在哪里? - Where's the difference between setObject:forKey: and setValue:forKey: in NSMutableDictionary? setObject:forKey:发送给不可变对象的变异方法 - setObject:forKey: mutating method sent to immutable object NSMutableDictionary上的setObject:forKey:是否分配? - Does setObject:forKey: on NSMutableDictionary do an allocation? [__NSDictionaryI setObject:forKey:]:无法识别的选择器已发送到实例 - [__NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance [NSDictionaryI setObject:forKey:]: 无法识别的选择器发送到实例 - [NSDictionaryI setObject:forKey:]: unrecognized selector sent to instance 如何重写setObject:forKey:方法(在Foundation Framework中) - how to override setObject: forKey: method (in Foundation Framework)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM