4 Replies Latest reply on Apr 28, 2014 1:10 PM by alitvak

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

    promethia73
      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
        • Re: [__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
          njarecha-esristaff
          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
          • Re: [__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
            promethia73
            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
            • Re: [__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
              njarecha-esristaff
              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
              • Re: [__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
                alitvak
                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