Crash when calling custom methods in custom subclass.
Crash when calling custom methods in custom subclass.
- Subject: Crash when calling custom methods in custom subclass.
- From: Adam Raney <email@hidden>
- Date: Thu, 28 Jul 2005 21:34:22 -0500
Hello all, I am a novice Cocoa programmer and am having some problems
getting my first project up and running. I have developed a few
sub-classes of NSObject to be used to assemble a quiz for a quizzing
program. I am trying to set up a method that will create the new class
(ACRQuizProblemRowElement) and call some of its methods to set it's
member variables.
Here's some relevent excerpts:
ACRQuizProblemRowElement.h :
#import <Cocoa/Cocoa.h>
@interface ACRQuizProblemRowElement : NSObject
{
NSString * format;
NSString * content;
NSArray * answers; // to be filled with NSStrings
bool isHeader;
}
- (void) setFormat: (NSString *)newFormat;
- (void) setContent: (NSString *)newContent;
- (void) setAnswers: (NSArray *)newAnswers;
- (void) setIsHeader: (bool)newIsHeader;
@end
---------
ACRQuizProblemRowElement.m
...
- (void) setFormat: (NSString *)newFormat
{
format = [NSString stringWithString: newFormat];
}
- (void) setContent: (NSString *)newContent
{
content = [NSString stringWithString: newContent];
}
- (void) setAnswers: (NSArray *)newAnswers
{
answers = [NSArray arrayWithArray: newAnswers];
}
- (void) setIsHeader: (bool)newIsHeader
{
isHeader = newIsHeader;
}
...
----------
ACRQuizBuilderController.m
...
- (IBAction)addHeaderRow:(id)sender
{
NSString *newContent = [headerEntry stringValue];
NSString *newFormat = @"text";
NSArray *newAnswers = [NSArray array];
bool newIsHeader = YES;
ACRQuizProblemRowElement *newElement;
[newElement setContent: newContent];
[newElement setFormat: newFormat];
[newElement setAnswers: newAnswers];
[newElement setIsHeader: newIsHeader];
}
...
----------
In the debugger, all works well until I reach [newElement setContent:
newContent];, then the program crashes. The crashReporter log shows
this, among other things:
PID: 519
Thread: 0
Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_INVALID_ADDRESS (0x0001) at 0x40803000
Thread 0 Crashed:
0 libobjc.A.dylib 0x909ad0f0 objc_msgSend + 16
1 ACRQuizBuilderController.ob 0x00059558 -[ACRQuizBuilderController
addHeaderRow:] + 204 (ACRQuizBuilderController.m:46)
2 com.apple.AppKit 0x936bf08c -[NSApplication
sendAction:to:from:] + 108
...
-----------
I am sure I made some rookie mistake here. If anyone could take the
time to point out my fault and explain the results I am seeing here, I
would really appreciate it.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden