首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Iphone >

新手提问,关于Exception的有关问题

2013-01-08 
新手提问,关于Exception的问题本帖最后由 z550946941 于 2012-12-20 16:33:01 编辑这是一本关于Objective-

新手提问,关于Exception的问题
本帖最后由 z550946941 于 2012-12-20 16:33:01 编辑 这是一本关于Objective-c的书中的例子,使用CodeBlocks编译运行,出现以下错误:
Uncaught exception NSInvalidArgumentException, reason: NSAutoreleasePool(instance) does not recognize length
各位大神看看又啥不对的地方
代码如下:


#import <Foundation/Foundation.h>

//----------------------------------------
@interface Tire : NSObject
@end //Tire

@implementation Tire
- (NSString *) description{
   return (@"I am a tire. I last a while.");
}//description
@end//Tire

//----------------------------------------
@interface AllWeatherRadial : Tire
@end //AllWeatherRadial

@implementation AllWeatherRadial
    -(NSString *) description{
        return (@"i am a tire for rain or shine.");
    }
@end

//----------------------------------------
@interface Engine : NSObject
@end//Engine

@implementation Engine
-(NSString *) description{
   return (@"I am an engine, Vrooom!");
}//description
@end //Engine

//----------------------------------------
@interface Slant6 : Engine
@end // Slant6
@implementation Slant6

    -(NSString *) description{
        NSLog(@"I am a slant-6. VROOOM!");
    }

@end //Slant6

//----------------------------------------
@interface Car : NSObject{
    Engine *engine;
    Tire *tires[4];
}

-(Engine *) engine;
-(void) setEngine: (Engine *) newEngine;

-(Tire *) tireAtIndex: (int) index;
-(void) setTire: (Tire *) tire atIndex:(int) index;

-(void) print;

@end //Car

@implementation Car

-(id) init{
    if(self == [super init]){
        engine = [Engine new];
        tires[0] = [Tire new];
        tires[1] = [Tire new];
        tires[2] = [Tire new];
        tires[3] = [Tire new];
    }
    return self;
}

-(Engine *)engine{
    return engine;
}

-(void) setEngine:(Engine *) newEngine{
    engine = newEngine;
}

-(Tire *) tireAtIndex:(int) index{
    if(index < 0 || index >3){
       NSLog(@"bad index (%d) in tireAtIndex", index);
       exit(1);
    }
    return tires[index];
}

-(void) setTire:(Tire *) tire atIndex:(int) index{
    if(index < 0 || index >3){


       NSLog(@"bad index (%d) in setTire:atIndex", index);
       exit(1);
    }

    tires[index] = tire;

}

-(void) print{

    NSLog(@"%@", engine);
    NSLog(@"%@", tires[0]);
    NSLog(@"%@", tires[1]);
    NSLog(@"%@", tires[2]);
    NSLog(@"%@", tires[3]);
}
@end //Car

// --------------------------------------------------
int main(int argc, const char * argv[]){
    Car *car = [Car new];
    //Engine *engine = [Engine new];
    Slant6 *slant6 = [Slant6 new];
    [car setEngine: slant6];

    int i;
    for(i = 0; i < 4; i++){
       //Tire *tire = [Tire new];
       Tire *tire = [AllWeatherRadial new];
       [car setTire: tire atIndex: i];
    }

    car.print;
    return 0;
}


[解决办法]
断点泡泡看,看问题在哪里

热点排行