Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8735069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:58:14+00:00 2026-06-13T09:58:14+00:00

When i run the my app, in this code there’s an error when i

  • 0

When i run the my app, in this code there’s an error when i try to remove the element from array. Why there’s this error? And How do to resolve this problem?

  if ([EnterWeightViewController withData]) {

    Database *db = [[Database alloc] init];
    [db openDB];
    [db createTable];
    NSArray *array = [db getAllPesi];
    int count = [self.weightHistory countOfWeightHistory]; //count = 5
    NSLog(@"Count of Array = %i", count);

    //-- Init Array
    for (int i =0; i< count; i ++) { 
        [self.weightHistory removeWeightAtIndex:i]; //error when i > 2
    }

    //-- Load Array
    for (WeightEntry *entry in array) {
        [self.weightHistory addWeight:entry];
    }

    //-- Reload Data
    [self.tableView reloadData];
}

 - (void)removeWeightAtIndex:(NSUInteger)weightIndex;{

  // Manually send KVO messages.
  [self willChange:NSKeyValueChangeRemoval 
   valuesAtIndexes:[NSIndexSet indexSetWithIndex:weightIndex]
          forKey:KVOWeightChangeKey];

  // Add to the front of the list.
  [self.weightHistory removeObjectAtIndex:weightIndex];

  // Manually send KVO messages.
  [self didChange:NSKeyValueChangeRemoval 
valuesAtIndexes:[NSIndexSet indexSetWithIndex:weightIndex]
         forKey:KVOWeightChangeKey];

}

error message: * Terminating app due to uncaught exception ‘NSRangeException’, reason: ‘* -[__NSArrayM removeObjectAtIndex:]: index 3 beyond bounds [0 .. 1]’
* First throw call stack:
(0x19ba012 0x1397e7e 0x195c1c4 0x9618 0x5622 0x3c2753 0x3c2a7b 0x3d0590 0x3d85bd 0x3d8eab 0x3da3d6 0x3da675 0x96fd780 0x3d9625 0x3db728 0x35da0b 0x35d990 0x96d1f7a 0x360d1a 0x360f14 0x3610c9 0x31233f 0x312552 0x2f03aa 0x2e1cf8 0x26ecdf9 0x26ecad0 0x192fbf5 0x192f962 0x1960bb6 0x195ff44 0x195fe1b 0x26eb7e3 0x26eb668 0x2df65c 0x2b2d 0x2a55)
libc++abi.dylib: terminate called throwing an exception

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:58:16+00:00Added an answer on June 13, 2026 at 9:58 am

    When i is equal to 3, you have already removed 3 items from your array (0, 1, 2). Now there are two remaining at positions 0 and 1. If you try to remove one at position 3, you’re outside the range.

    Call removeAllObjects on the array instead of going through the loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to run my php App from Ubuntu Server 11.10. This App works
I get this error when I run a django app ( dpaste ) Template
I keep getting this error when I run my web app (asp.net mvc) in
When I run this code on my computer with the help of Google App
I am getting this error in console while i m run app in simulator
I got an .ipa file from a customer (without source code access). This app
im really desperate right now, ive tried everything. Everytime i run my app this
i create some project but when start App. How to Run this App one
Having this errors when trying to compile/run my app using Maven. I've succeeded to
What's incorrect in this manifest to run an app as Admin? It works fine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.