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

7562
4
Jump to solution
04-15-2012 02:47 AM
LucaAlferi1
New Contributor
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
0 Kudos
1 Solution

Accepted Solutions
NimeshJarecha
Esri Regular Contributor
Just change your didExecuteWithIdentifyResults code as following and it won't crash...

- (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

View solution in original post

0 Kudos
4 Replies
NimeshJarecha
Esri Regular Contributor
Just change your didExecuteWithIdentifyResults code as following and it won't crash...

- (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
0 Kudos
LucaAlferi1
New Contributor
Just change your didExecuteWithIdentifyResults code as following and it won't crash...

- (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
0 Kudos
NimeshJarecha
Esri Regular Contributor
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
0 Kudos
AlexanderLitvak
New Contributor II
Hello, I'm getting same error message but I'm running Task for Offline Routing.
It is fail on initializing AGSRouteTask in this section, in the last row:
SError* error = nil;
NSString* docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* fullPath = [docDir stringByAppendingPathComponent:@"NetworkData.bundle/RuntimeSanFrancisco.geodatabase"];
_routeTask = [AGSRouteTask routeTaskWithDatabasePath:fullPath network:@"Streets_ND" error:&error];

All required files are copied in to Document folder and before I'm initializing task I validate existence of *.geodatabase and Streets_ND.
Installed SDK Runtime version 10.2.3.

Thanks,
Alex
0 Kudos