Objc_msgSend and app crash
When I trying to launch my app on simulator (3.1.3 , Xcode 3.1.4), it shows me objc_msgSend and application does not launch. This happens only when I alloc NSMUtable Array This is my code part, in viewDidLoad,
-(void)viewDidLoad{
locationArray = [[NSMutableArray alloc] initWithObjects:@"new delhi", @"faridabad",@"meerut"];
str1=[locationArray objectAtIndex:0];
str2=[locationArray objectAtIndex:1];
[super viewDidLoad];
}
Then I want to use locationArray objects in following method;
-(CLLocationCoordinate2D) addressLocation1{
double latitude = 0.0;
double longitude = 0.0;
NSString *str= [locationArray NSString *str= [locationArray objectAtIndex:0];
//NSString *str= @"new delhi"
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",
[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
NSArray *listItems = [locationString componentsSeparatedByString:@","];
if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {
latitude = [[listItems objectAtIndex:2] doubleValue];
longitude = [[listItems 开发者_运维百科objectAtIndex:3] doubleValue];
}
else {
//Show error
}
CLLocationCoordinate2D location;
location.latitude = latitude;
location.longitude = longitude;
return location;
}
problem occur only when alloc the locationArray, whats wrong with me, please help thanks
locationArray = [[NSMutableArray alloc] initWithObjects:@"new delhi", @"faridabad",@"meerut"];
Try
locationArray = [[NSMutableArray alloc] initWithObjects:@"new delhi", @"faridabad",@"meerut", nil];
From The NSArray docs you see that for initWithObjects:
it requires termination with nil
. If you don't want to do that, and you know how many you have, you can use initWithObjects:count:
精彩评论