1
votes

I run this code:

- (void)unitButtonButtonTapped:(id)sender {
    [_label setString:@"Last button: Unembossed square"];
    MilitaryUnits *target = nil;
    target = [Peasants militaryUnits];
    target.position = ccp(100, 450);
    [self addChild:target];
}

And I get this error: * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Argument must be non-nil'

These are my .h and .m class files

#import "cocos2d.h"

@interface MilitaryUnits : CCSprite {
    int _experience;
    int _number_of_units;
    int _stamina;
    int _armor_level;
    int _weapon_levell;
}

@property (nonatomic, assign) int experience;
@property (nonatomic, assign) int number_of_units;
@property (nonatomic, assign) int stamina;
@property (nonatomic, assign) int armor_level;
@property (nonatomic, assign) int weapon_levell;

@end

@interface Peasants : MilitaryUnits{

}
+(id)militaryUnits;

@end

#import "MilitaryUnits.h"

@implementation MilitaryUnits

@synthesize number_of_units = _number_of_units;
@synthesize stamina = _stamina;
@synthesize experience = _experience;
@synthesize armor_level = _armor_level;
@synthesize weapon_levell = _weapon_levell;

@end

@implementation Peasants

+ (id)militaryUnits {

    Peasants *militaryUnits = nil;
    if ((militaryUnits = [[[super alloc] initWithFile:@"Target.png"] autorelease])) {
    }
    return militaryUnits;

}

@end

Note, I'm using cocos 2d

1
Please post the full errormrssage. - user529758
I don't see a single "initWithFile" declared in your ".h" interface file. - Michael Dautermann
We need the stack trace to properly diagnose the problem. The stack trace looks like a list of functions/methods, and should come just before the error you posted. - Tom Dalling
The suspicious part to me is super alloc in + (id) militaryUnits; I don't think that will be defined. Try replacing it with MilitaryUnits alloc instead. - Kevin Grant

1 Answers

2
votes

looks to me like your sprite is nil, ie the file "Target.png" is not found. Make certain the file name has the same case (in finder) as you spelled out in your code, and that the file is included in the target's membership in Xcode.

Also

+ (id)militaryUnits {

    Peasants *militaryUnits;
    if ((militaryUnits = [[[super alloc] initWithFile:@"Target.png"] autorelease])) {
        return militaryUnis;
    } else {
        CCLOGERROR(@"your favorite whine style for errors like file not found");
        return nil;
    }  
}