图像为空 [NSCFDictionary setObject:forKey:]: 尝试插入 nil 值 (key:)

发布于 2024-12-22 04:36:54 字数 2754 浏览 3 评论 0原文

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

我正在尝试使用游戏中心向其插入在线排行榜。然而

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

我已将其插入此处:

    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 和真实设备上都尝试过,但出现了相同的错误。

我还应该做什么?

i have this game app a cocos2d which i downloaded it is an open source game...

i am trying to insert an online leaderboard to it using gamecenter. however

the image that i insert seems to be crashing the game.

i have inserted it here:

    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;
}

the

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

thats the one then i edited the button3callback like this :

-(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");
            }
        }];
    }
}

now i am having this errors :

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)

i make it sure that the image is in its proper place... and i dont know why it is nil?

i have tried on both sim and real device and i have the same errors.

what else should i do ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嗳卜坏 2024-12-29 04:36:54

找到答案

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

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

我已将其替换为真实的 png 图像,现在效果很好..

感谢所有回复的人:)

Found the Answer

i have inserted an image that is not a real png file...

thats why it says that the image is null because it couldn't find a real png file

i have replaced it with a real png image and now it works well ..

thanks to all who replied :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文