Image为null [NSCFDictionary setObject:forKey:]:尝试插入nil值(键:)

时间:2011-12-20 03:40:13

标签: iphone ios game-center

我有这个游戏应用程序cocos2d我下载它是一个开源游戏...

我正在尝试使用gamecenter插入一个在线排行榜。然而

我插入的图像似乎正在崩溃游戏。

我已将其插入此处:

    MenuItem *button1 = [MenuItemImage itemFromNormalImage:@"playAgainButton.png" selectedImage:@"playAgainButton.png" target:self selector:@selector(button1Callback:)];
    MenuItem *button2 = [MenuItemImage itemFromNormalImage:@"changePlayerButton.png" selectedImage:@"changePlayerButton.png" target:self selector:@selector(button2Callback:)];
    MenuItem *button3 = [MenuItemImage itemFromNormalImage:@"blank1.png" selectedImage:@"blank1.png" target:self selector:@selector(button3Callback:)];

    Menu *menu = [Menu menuWithItems: button1, button2, button3, nil];

    [menu alignItemsVerticallyWithPadding:9];
    menu.position = ccp(160,48);

    [self addChild:menu];

    return self;
}

MenuItem *button3 = [MenuItemImage itemFromNormalImage:@"blank1.png" selectedImage:@"blank1.png" target:self selector:@selector(button3Callback:)];

那就是那个我编辑了button3callback,如下所示:

-(void)button3Callback:(id)sender
{
    GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] init];
    if (leaderboardRequest != nil)
    {
        NSLog(@"leaderboardrequest is not equal nil");
        leaderboardRequest.playerScope = GKLeaderboardPlayerScopeGlobal;
        leaderboardRequest.timeScope = GKLeaderboardTimeScopeAllTime;
        leaderboardRequest.range = NSMakeRange(1,10);
        [leaderboardRequest loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error) {
            if (error != nil)
            {
                // handle the error.
                NSLog(@"ERROR : %@",[error localizedDescription]);
            }
            if (scores != nil)
            {
                // process the score information.

                for (id thisScore in scores) {
                    NSLog(@"Score %@  ", thisScore);
                }
            }
            else {
                NSLog(@"Scores == nil");
            }
        }];
    }
}

现在我遇到了这个错误:

2011-12-20 11:29:40.984 tweejump[2936:707] Image is Null
2011-12-20 11:29:40.988 tweejump[2936:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary setObject:forKey:]: attempt to insert nil value (key: blank1.png)'
*** First throw call stack:
(0x31cca8bf 0x31a3a1e5 0x31cca7b9 0x31cca7db 0x31c376bb 0x35dc9 0x2f63f 0x2f5c5 0x25385 0x252f9 0x2522f 0x43cc7 0x429bb 0x4235f 0x2e95f 0x2f515 0xf26f 0x358db61d 0x31c9ea63 0x31c9e6c9 0x31c9d29f 0x31c204dd 0x31c203a5 0x31d2cfed 0x327b0743 0x2873 0x282c)

我确保图像在适当的位置......我不知道为什么它是零?

我已尝试使用SIM卡和真实设备,我也有同样的错误。

我还应该做什么?

1 个答案:

答案 0 :(得分:0)

找到答案

我插入的图像不是真正的png文件......

这就是为什么它说图像为空因为找不到真正的png文件

我用真正的png图像替换它,现在效果很好..

感谢所有回复的人:)