My application crashing Please help me out.

Posted by kiran kumar on Stack Overflow See other posts from Stack Overflow or by kiran kumar
Published on 2011-01-05T12:12:40Z Indexed on 2011/01/05 12:54 UTC
Read the original article Hit count: 170

Filed under:

My Application get crashing ...

its loading data of all the cities... and when i click its displaying my detailed view controller.... when iam getting back from my controller... and selecting another city my application get crashed.. Please help me out.

To get idea i am pasting my code.

#import "CityNameViewController.h"
#import "Cities.h"
#import "XMLParser.h"
#import "PartyTemperature_AppDelegate.h"
#import "CityEventViewController.h"

@implementation CityNameViewController
//@synthesize aCities;
@synthesize appDelegate;
@synthesize currentIndex;
@synthesize aCities;
/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"Cities";
    appDelegate=(PartyTemperature_AppDelegate *)[[UIApplication sharedApplication]delegate];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        // Return the number of rows in the section.

    return [appDelegate.cityListArray count];
}
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 95.0f;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.textColor = [[[UIColor alloc] initWithRed:0.2 green:0.2 blue:0.6 alpha:1] autorelease];
    cell.detailTextLabel.textColor = [UIColor blackColor];
    cell.detailTextLabel.font=[UIFont systemFontOfSize:10];
    if (indexPath.row %2 == 1) {
        cell.backgroundColor = [[[UIColor alloc] initWithRed:0.87f green:0.87f blue:0.87f alpha:1.0f] autorelease];
    } else {
        cell.backgroundColor = [[[UIColor alloc] initWithRed:0.97f green:0.97f blue:0.97f alpha:1.0f] autorelease];
    }
}

    // Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
        cell.selectionStyle= UITableViewCellSelectionStyleBlue;
            //      cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    cell.backgroundColor=[UIColor blueColor];
    }
//  aCities=[appDelegate.cityListArray objectAtIndex:indexPath.row];
//  cell.textLabel.text=aCities.city_Name;
    cell.textLabel.text=[[appDelegate.cityListArray objectAtIndex:indexPath.row]city_Name];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //http://compliantbox.com/party_temperature/citysearch.php?city=Amsterdam&latitude=52.366125&longitude=4.899171
    NSString *url;
    aCities=[appDelegate.cityListArray objectAtIndex:indexPath.row];
    if ([appDelegate.cityListArray count]>0){
    url=@"http://compliantbox.com/party_temperature/citysearch.php?city=";
    url=[url stringByAppendingString:aCities.city_Name];
    url=[url stringByAppendingString:@"&latitude=52.366125&longitude=4.899171"];
    NSLog(@"url value is %@",url);
    [self parseCityName:[[NSURL alloc]initWithString:url]];
    }
}

-(void)parseCityName:(NSURL *)url{
    NSXMLParser *xmlParser=[[NSXMLParser alloc]initWithContentsOfURL:url];
    XMLParser *parser=[[XMLParser alloc] initXMLParser];
    [xmlParser setDelegate:parser];
    BOOL success;
    success=[xmlParser parse];
    if (success) {
        NSLog(@"Sucessfully parsed");
        CityEventViewController *cityEventViewController=[[CityEventViewController alloc]initWithNibName:@"CityEventViewController" bundle:nil];
        cityEventViewController.index=currentIndex;
        [self.navigationController pushViewController:cityEventViewController animated:YES];
        [cityEventViewController release];
        cityEventViewController=nil;
    }
    else {
        NSLog(@"Try it Idoit");
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert!" message:@"Event Not In Radius" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];
    }


}
- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [aCities release];
    [super dealloc];
}
@end

And the error is

* Terminating app due to uncaught exception 'NSRangeException', reason: ' -[NSMutableArray objectAtIndex:]: index 1 beyond bounds for empty array' ** Call stack at first throw:

© Stack Overflow or respective owner

Related posts about iphone