Possible Duplicate:
EXC_BAD_ACCESS when trying to get iPhone screen dimensions
I have the following code snippet in objective-c that automatically sets some variables to a number of presets. However, on the marked line I get a “Program received signal: EXC_BAD_ACCESS” exception.
What confuses me is that the line above is identical, just with a different value. If line 1 does not throw an exception, why should line 2? What can I do about this?
Thanks in advance!
Sterren
- (IBAction)presetPressed:(id)sender {
if(self.userEnteringNumber) [self enterPressed];
double xVal;
double aVal;
double bVal;
NSString *preset = [sender currentTitle];
if ([preset isEqualToString:@"1"]) {
xVal = 1;
aVal = 2;
bVal = 3;
} else if ([preset isEqualToString:@"2"]) {
xVal = 1.5;
aVal = 2.9;
bVal = 3.0;
} else if ([preset isEqualToString:@"3"]) {
xVal = -1;
aVal = -2;
bVal = -3;
}
[self.variables setValue:[NSNumber numberWithDouble:xVal] forKey:@"x"];
[self.variables setValue:[NSNumber numberWithDouble:aVal] forKey:@"a"];
[self.variables setValue:[NSNumber numberWithDouble:bVal] forKey:@"b"];
self.xVar.text = [NSString stringWithFormat:@"= %@", xVal];
self.aVar.text = [NSString stringWithFormat:@"= %@", aVal]; //EXC_BAD_ACCESS here
self.bVar.text = [NSString stringWithFormat:@"= %@", bVal];
[self calculateResult];
}
xVal,aVal,bValare all primitive doubles, but yet your string format is looking for an object via%@.try replacing
%@with%f(or%gif you prefer scientific notation):