0

I am doing parsing, in my parsearray having only two data number of alerts and number of events these are fine. When we are finding the value like

NSString *alertcount = [[xmlparseArray objectAtIndex:indexPath.row ]objectForKey:@"alerts"];

and assigning these string value into label

mylabel.text = [NSString stringWithFormat:@"%@", alertcount];

same for Events.

then it becomes crash. It says:

index 0 beyond out of empty Array

And these parsing I am using in @RootViewController:

UITableViewController {


}

not using custom cell. In this rootviewcontroller class we are using 7 row(these are constant) and I want to assign at row number 5 the value of alert (i.e. mylabel.text = [NSString stringWithFormat:@"%@", alertcount]) at the right position of cell number 5 same is cell number 6.

4
  • 2
    In your case, you should not set the no.of rows as 7constant and if your array count was 2 but indexpath.row goes upto 7. this will lead to get crash as empty arrays have been found. Commented Jun 9, 2011 at 10:04
  • 3
    Also, you can accept answers to attract a wider range of people to help you Commented Jun 9, 2011 at 10:06
  • Yes @prasanna these seven rows is constant and we are assign like cell.textlabel.text = @"Alert"; i am doing deviding sections means e sections and return 1st section 3 row and section section return [xmlParseArray count]; and 3rd section return 2 row but at section at 2nd ([xmlParseArray count];) generate no row. Commented Jun 9, 2011 at 10:17
  • However you are using indexpath.row to retrive the array since you had only 2elements there. you should write by your own index then. Commented Jun 9, 2011 at 10:35

1 Answer 1

1

Your xmlparseArray might be empty. Check if you have any elements in the array. Pls show the code where you populate the array so that we can have a better idea of where you are going wrong

Sign up to request clarification or add additional context in comments.

7 Comments

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if([elementName isEqualToString:@"Init"]){ } [xmlValue setString:@""]; } } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { [xmlValue appendString:string]; }
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if ([elementName isEqualToString:@"alerts"]) { [currentItem setValue:[NSString stringWithString:xmlValue] forKey:elementName]; }else if ([elementName isEqualToString:@"events"]) { [currentItem setValue:[NSString stringWithString:xmlValue] forKey:elementName]; }
else if ([elementName isEqualToString:@"Init"]) { [self.xmlParseArray addObject:[NSDictionary dictionaryWithDictionary:currentItem]]; } NSLog(@"xmlArray is : %@",xmlParseArray);
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 7;
You'd better put all this stuff in the question ... this way it's impossible to understand!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.