Saturday, September 28, 2013

Novice questions about issues of Exception

posts by z550946941 on 2012-12-20 16:33:01 Edit
This is a book about Objective-c example, using CodeBlocks compile and run, the following error:
Uncaught exception NSInvalidArgumentException, reason: NSAutoreleasePool (instance) does not recognize length
You look great God and what is wrong with
Code is as follows:
 
# Import

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

Reply:
Breakpoints Bubble Look, look where the problem
Reply:
quote 1 floor yuhuangc reply:
breakpoint bubble look, look where the problem lies

Thank you reply that he put a piece of code was wrong, had the return, I NSLog print directly, no return, that is, the following code
 @ interface Slant6: Engine 
@ End / / Slant6
@ Implementation Slant6

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

@ End / / Slant6

Reply:
cited two floor z550946941 reply:
quote 1 floor yuhuangc reply: Breakpoint bubble look, look where the problem
Thank you reply that he put a piece of code was wrong, had the return, I NSLog print directly, no return, that is, the following code
Objective C code? 123456789 @ interface Slant6: Engine @ end / / Slant6 @ implementation Slant6 - (NS ......

Right, so many breakpoints, what can come out of this problem.

No comments:

Post a Comment