I have this code below. The thing is, each time I click on the “SPIN” ccmenuitem, the program crashes with a “Program received signal: SIGABRT”
Here’s the output in the console:
2011-07-29 13:52:52.906 HelloWorld[1031:207] -[NSCFString shuffle]: unrecognized selector sent to instance 0x6833c90
2011-07-29 13:52:52.976 HelloWorld[1031:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString shuffle]: unrecognized selector sent to instance 0x6833c90'
I don’t know what’s wrong, my
And here is my code.
`#import <Foundation/Foundation.h>
#import "cocos2d.h"
@interface GameScene : CCLayer {
NSMutableArray * answersArray; //holds all valid answers
NSMutableArray * lettersArray; //holds placement of letters to display
NSMutableArray * userAnswerArray; //holds user's answer to check and submit
NSString * THEWORD; //the word
}
+(id) scene;
....
- (void) spinWord;
- (void) playWord;
@end`
And this implementation:
`
@implementation GameScene
+(id) scene { ... }
-(id) init
{
if( (self=[super init])) {
...//everything is initialized
[self initImages]
...
}
}
- (void) initImages
{
....
CCMenuItem *menuItem1 = [CCMenuItemImage itemFromNormalImage:@"PLAYunselected.png" selectedImage:@"PLAYselected.png" target:nil selector:@selector(onPlayWord)];
CCMenuItem *menuItem2 = [CCMenuItemImage itemFromNormalImage:@"SPINunselected.png" selectedImage:@"SPINselected.png" target:self selector:@selector(spinWord)];
CCMenu *menu = [CCMenu menuWithItems:menuItem1, menuItem2, nil];
[menu alignItemsHorizontally];
menu.position = ccp(72, 198);
[self addChild:menu z:2];
}
- (void) spinWord{
//NSLog(@"%@",lettersArray); <---if I uncomment this line, I get an EXC_BAD_ACCESS message instead
[lettersArray shuffle]; // <--- this line causes the SIGABRT signal, even if it's initialized.
NSLog(@"%@",lettersArray);
...
}
@end
`
Please help me out. Is this a memory management problem? If so, how do I fix it?
Thank you very much!
That error always means exactly what it reads like it means. You have sent a message to an object that does not understand that message (meaning the object does not have a method to handle such a request). This however can also mean you are sending a message to an object that does not exist.
If you try to access a bad array index (or the index of an array that does not actually exist) you get bad access. If you try to access a method that does not exist, or a method of an object that does not exist, you get a unrecognized selector message.
I do not see you allocating or initializing your arrays. I don’t know what shuffle is, you have not posted code for it. It may be a built in method for all I know. I am fairly certain that all you need to do is allocate and initialize your arrays.