2 Replies - 5611 Views - Last Post: 22 August 2012 - 03:59 AM

#1 Elro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-August 12

terminate called throwing an exception(lldb)

Posted 21 August 2012 - 06:43 AM

Hi all, brand new to these forums so I apologize in advance if this is posted in the wrong place.

I am brand new to Objective-C programming and teaching myself using Objective-C for absolute beginners (which demonstrates and earlier version of Xcode and working on Xcode 4.3.3 (probably part of the problem) and various sources on the web. I have become stuck on an exercise where I am getting the exception(lldb) and have no idea where I am going wrong. I get a build succeed then the error.
code as follows:
[#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{

    @autoreleasepool {
        
        // insert code here...
        NSMutableArray *bookList = [NSArray arrayWithObjects:@"Moby Dick",@"Frankenstein", @"Tom Sawyer",nil]; 
                             
        int count;
        count= bookList.count;
        for (int y=0;y<count;y++) 
        {
            NSLog(@"Book Title is %@", [bookList objectAtIndex:y]);
            
            [bookList addObject:(@"Huckleberry Finn")];  
                                        
        }
    
    return 0;
    }}
]
and the console reads:
[2012-08-21 15:37:56.445 Comparison[1142:403] Book Title is Moby Dick
2012-08-21 15:37:56.448 Comparison[1142:403] -[__NSArrayI addObject:]: unrecognized selector sent to instance 0x106d14580
2012-08-21 15:37:56.449 Comparison[1142:403] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI addObject:]: unrecognized selector sent to instance 0x106d14580'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff86449f56 __exceptionPreprocess + 198
	1   libobjc.A.dylib                     0x00007fff89951d5e objc_exception_throw + 43
	2   CoreFoundation                      0x00007fff864d61be -[NSObject doesNotRecognizeSelector:] + 190
	3   CoreFoundation                      0x00007fff86436e23 ___forwarding___ + 371
	4   CoreFoundation                      0x00007fff86436c38 _CF_forwarding_prep_0 + 232
	5   Comparison                          0x0000000106c36e3a main + 266
	6   Comparison                          0x0000000106c36d24 start + 52
)
terminate called throwing an exception(lldb) 
]


again apologies for the very simplistic problem - any guidance will be greatly appreciated..

Elro

This post has been edited by jimblumberg: 21 August 2012 - 06:49 AM
Reason for edit:: Added missing Code Tags, Please learn to use them.


Is This A Good Question/Topic? 0
  • +

Replies To: terminate called throwing an exception(lldb)

#2 GWatt  Icon User is offline

  • member icon

Reputation: 264
  • View blog
  • Posts: 3,059
  • Joined: 01-December 05

Re: terminate called throwing an exception(lldb)

Posted 21 August 2012 - 11:33 AM

You have to use the NSMutableArray initializer, otherwise you can't resize it.
NSMutableArray *booklist = [NSMutableArray arrayWithObjects: ...];


Was This Post Helpful? 1
  • +
  • -

#3 Elro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-August 12

Re: terminate called throwing an exception(lldb)

Posted 22 August 2012 - 03:59 AM

View PostGWatt, on 21 August 2012 - 11:33 AM, said:

You have to use the NSMutableArray initializer, otherwise you can't resize it.
NSMutableArray *booklist = [NSMutableArray arrayWithObjects: ...];


That sorted it many thanks GWatt!

Thanks for the help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1