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

  • Home
  • SEARCH
  • 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 6537937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:40:33+00:00 2026-05-25T10:40:33+00:00

I have a block of code which when executed gives me this error. And

  • 0

I have a block of code which when executed gives me this error. And I am relatively new, I can’t seem to fix the problem.

Error:
2011-09-06 12:31:06.094 ForceGauge[266:707] CoreAnimation: ignoring exception: * -[NSMutableArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]

-(void)peakCollector:(NSMutableArray *)testarray {

    NSUInteger totalRows = [testarray count];

    NSMutableArray *percentArray = [[NSMutableArray alloc]initWithObjects:0, nil];

    if(forcecontroller.selectedSegmentIndex==0)
        testarray = lbData;
    else if(forcecontroller.selectedSegmentIndex==1)
        testarray = kgData;     
    else if(forcecontroller.selectedSegmentIndex ==2)
        testarray = ozData;
    else if(forcecontroller.selectedSegmentIndex ==3)
        testarray = newtonData;

    for(int i = 0; i< totalRows-1; i++) {

        if ([[testarray objectAtIndex:i+1] doubleValue] >= 1.2 * [[testarray objectAtIndex:i] doubleValue]) {
            percentArray = [testarray objectAtIndex:i];

            DatabaseTable *tableVC = [[DatabaseTable alloc] initWithStyle:UITableViewStylePlain];
            [self.navigationController pushViewController:tableVC animated:YES];

            if(forcecontroller.selectedSegmentIndex==0)
                [tableVC copydatabase:percentArray];
            else if(forcecontroller.selectedSegmentIndex==1)
                [tableVC copydatabase:kgData];
            else if(forcecontroller.selectedSegmentIndex==2)
                [tableVC copydatabase:ozData];
            else if(forcecontroller.selectedSegmentIndex==3)
                [tableVC copydatabase:newtonData];

            [tableVC release];
        } else {
            [analogData removeAllObjects];
        }
    }
}
  • 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-05-25T10:40:34+00:00Added an answer on May 25, 2026 at 10:40 am

    There are multiple issues here:

    1) NSArrays can only contains NSObjects.

    In your code, you are initializing your NSArray using [[NSMutableArray alloc]initWithObjects:0, nil];, but 0 is an atomic type, not an NSObject
    (and basically 0 is the same value as nil (nil and NULL are typically equal to 0, interpreted as the id and void* types, respectively)

    You have to encapsulate your 0 value in an NSNumber instead :

    [[NSMutableArray alloc]initWithObjects:[NSNumber numberWithInt:0], nil];
    

    Then retrieve the NSNumber using [percentArray objectAtIndex:0] and finally convert back the retrieve NSNumber to int using NSNumber‘s intValue method:

    NSNumber* number = [percentArray objectAtIndex:0]; // returns an NSNumber which is an NSObject encapsulating numbers, see Apple's documentation
    int val = [number intValue]; // retrieve the integer value encapsulated in the NSNumber
    // or directly:
    // int val = [[percentArray objectAtIndex:0] intValue];
    

    2) The exception you got is in fact elsewhere and is much more subtle: you are retrieving the [testarray count] value in an NSUInteger variable, which is an unsigned type. Then totalRows-1 will do some tricky things if totalRows is equal to 0 (which is obviously the case considering the exception you have).

    As totalRows is an NSUInteger, when it is equal to 0, totalRows-1 will not be equal to -1, but to… (NSUInteger)-1 (-1 interpreted as an unsigned integer), which is 0xFFFFFFFF, or namely the maximum value of the NSUInteger type!

    This is why i is always less than this totalRows-1 value (as this value is not -1 but 0xFFFFFFFF = NSUInteger_MAX).

    To solve this issue, cast your totalRows variable to an NSInteger value, or add a condition in your code to treat this special case separately.

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

Sidebar

Related Questions

I have this block of code: users = Array.new users << User.find(:all, :conditions =>
I have following Code Block Which I tried to optimize in the Optimized section
I have a block of preformatted code (<pre>) which overflows horizontally so there is
I have a txt file which contains a google adsense code block and I'm
I have a custom XML file format which can contain blocks of code within
I have this 3 lines of code which I use to hold the state
So in Code::Blocks in Ubuntu (latest). I have a project in which I load
I have a block of code that works and I wanted to ask what
I have a block of code that basically intializes several classes, but they are
I have a block of code that is repeated within a DB2 stored procedure.

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.