+ Reply to Thread
Results 1 to 4 of 4

Thread: [__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'

  1. #1
    Luca Alferi
    Join Date
    Apr 2012
    Posts
    18
    Points
    0
    Answers Provided
    0


    0

    Default [__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'

    i used the identify demo project to create my application. When i click out of extent of the dinamicLayer, application crashed with this error;

    2012-04-15 12:42:45.037 iSIT[1427:11f03] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'

    i tried to use alert view when click out of extent, but don't works.

    Please Help me

  2. #2
    Nimesh Jarecha

    Join Date
    Oct 2009
    Posts
    883
    Points
    489
    Answers Provided
    105


    0
    This post is marked as the answer

    Default Re: [__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'

    Just change your didExecuteWithIdentifyResults code as following and it won't crash...

    Code:
    - (void)identifyTask:(AGSIdentifyTask *)identifyTask operation:(NSOperation *)op didExecuteWithIdentifyResults:(NSArray *)results {
        
        //clear previous results
        [self.graphicsLayer removeAllGraphics];
        
        if ([results count] > 0) {
                    
            //add new results
            AGSSymbol* symbol = [AGSSimpleFillSymbol simpleFillSymbol];
            symbol.color = [UIColor colorWithRed:0 green:0 blue:1 alpha:0.5];
            
            // for each result, set the symbol and add it to the graphics layer
            for (AGSIdentifyResult* result in results) {
                result.feature.symbol = symbol;
                [self.graphicsLayer addGraphic:result.feature];
            }
            
            //set the callout content for the first result
            //get the state name
            NSString *stateName = [((AGSIdentifyResult*)[results objectAtIndex:0]).feature.attributes objectForKey:@"STATE_NAME"]; 
            self.mapView.callout.title = stateName;
            self.mapView.callout.detail = @"Click for more detail..";
            
            //show callout
            [self.mapView showCalloutAtPoint:self.mappoint forGraphic:((AGSIdentifyResult*)[results objectAtIndex:0]).feature animated:YES];
        }
        else {
            
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Identify Result"
                                                            message:@"No Result Found!"
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
            [alert show];
            [alert release];
        }
        
        //call dataChanged on the graphics layer to redraw the graphics
        [self.graphicsLayer dataChanged];	
    }
    Regards,
    Nimesh

  3. #3
    Luca Alferi
    Join Date
    Apr 2012
    Posts
    18
    Points
    0
    Answers Provided
    0


    0

    Default Re: [__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'

    Quote Originally Posted by nrjarecha View Post
    Just change your didExecuteWithIdentifyResults code as following and it won't crash...

    Code:
    - (void)identifyTask:(AGSIdentifyTask *)identifyTask operation:(NSOperation *)op didExecuteWithIdentifyResults:(NSArray *)results {
        
        //clear previous results
        [self.graphicsLayer removeAllGraphics];
        
        if ([results count] > 0) {
                    
            //add new results
            AGSSymbol* symbol = [AGSSimpleFillSymbol simpleFillSymbol];
            symbol.color = [UIColor colorWithRed:0 green:0 blue:1 alpha:0.5];
            
            // for each result, set the symbol and add it to the graphics layer
            for (AGSIdentifyResult* result in results) {
                result.feature.symbol = symbol;
                [self.graphicsLayer addGraphic:result.feature];
            }
            
            //set the callout content for the first result
            //get the state name
            NSString *stateName = [((AGSIdentifyResult*)[results objectAtIndex:0]).feature.attributes objectForKey:@"STATE_NAME"]; 
            self.mapView.callout.title = stateName;
            self.mapView.callout.detail = @"Click for more detail..";
            
            //show callout
            [self.mapView showCalloutAtPoint:self.mappoint forGraphic:((AGSIdentifyResult*)[results objectAtIndex:0]).feature animated:YES];
        }
        else {
            
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Identify Result"
                                                            message:@"No Result Found!"
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
            [alert show];
            [alert release];
        }
        
        //call dataChanged on the graphics layer to redraw the graphics
        [self.graphicsLayer dataChanged];	
    }
    Regards,
    Nimesh
    I love you
    Thanks

  4. #4
    Nimesh Jarecha

    Join Date
    Oct 2009
    Posts
    883
    Points
    489
    Answers Provided
    105


    1

    Default Re: [__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'

    You're welcome!

    If a post provides the answer to your question, then we encourage you to mark the post as "the answer" by activating the green check mark right of the post. You can also "vote" on posts that you find helpful by clicking the blue caret mark. More information about the ArcGIS Discussion Forums MVP Program found here.



    Thank you,
    Nimesh

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts