1

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:

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

This is the showAchievements method: Code:

- (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? 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. So I search for where this NSLog is and it is in GameCenterManager.m, a file necessary for Game Center I think. 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!

4

2 回答 2

3

我猜答案就在您发布的代码中:

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

您不能将 nil 键插入字典。您是否在做类似 [myDictionary setObject:foo forKey:bar] 的事情,其中​​ 'bar' 为 nil?

顺便说一句,您也不能将 nil 值插入字典,但这似乎不是错误原因所表明的。您可以调用[myDictionary setValue:nil forKey:bar](只要 bar 不为零) - 这会从字典中删除键。如果你想表示一个“nil”值,你可以将NSNull对象插入到字典中。但是键 - 键必须始终为非零。

于 2011-08-28T04:29:51.407 回答
1

From the log it seems like the key profileImage equals nil which means that there is no data for that key in your NSDictionary.

于 2011-08-28T03:43:39.633 回答