Re: Error, but why?
Re: Error, but why?
- Subject: Re: Error, but why?
- From: Chris Boot <email@hidden>
- Date: Fri, 02 Nov 2001 20:37:36 +0100
>
So, I'm following along with this example for a Foundation Tool from a
>
book due in December. Here is the code for main.m, which builds without
>
error:
>
>
#import <Foundation/Foundation.h>
>
>
int main (int argc, const char * argv[])
>
{
>
NSMutableArray *array;
>
int i;
>
NSNumber *number;
>
>
NSAutoreleasePool *pool = [ [NSAutoreleasePool alloc] init];
>
>
array = [ [NSMutableArray alloc] init];
>
for ( i = 0; i < 10; i++ )
>
{
>
number = [ [NSNumber alloc] init];
^^^^
You're not actually giving the NSNumber instance a number to use. Shouldn't
the underligned text read "initWithInt:i"? That would make the line:
number = [[NSNumber alloc] initWithInt:i];
Also, you're leaking an instance of NSNumber every time you go through this
loop, so watch it. I would suggest using:
number = [NSNumber numberWithInt:i];
>
[array addObject: number];
>
}
>
>
NSLog(@"array = %@", array);
>
[array release];
>
[pool release];
>
return 0;
>
}
>
//end code
>
>
However, when I build and run (hammer & monitor icon) I get an "Error from
>
Executable Runner" message:
>
>
2001-11-02 11:07:18.489 lottery[563] *** Uncaught exception:
>
<NSInvalidArgumentException> *** -[NSCFArray addObject:]: attempt to
>
insert nil
>
>
lottery has exited with status 255.
>
//end error message
>
>
I'm supposed to get something like:
>
>
2001-11-02 11:07:18.489 lottery[563] array = (0, 1, 2, . . .9)
>
lottery has exited with status 0.
>
>
So, can anyone give me a clue or explanation as to what's going on? This
>
code was originally written some months ago with OS X 10.0.x and related
>
tools. I'm now on 10.1--OS & Tools. Did I miss something in the release
>
notes? Thank, as always.
>
>
Brian E. Howard
>
Cocoa Cult Central
>
tooling along, slowly
>
_______________________________________________
>
cocoa-dev mailing list
>
email@hidden
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
--
Chris Boot
email@hidden
"Use the source, Luke." - Obi-wan GNUobi