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 7775043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:31:51+00:00 2026-06-01T17:31:51+00:00

Iam getting an EXC_BAD_ACCESS all the time and I cannot figure out why… Simple

  • 0

Iam getting an EXC_BAD_ACCESS all the time and I cannot figure out why…

Simple task:

The Parser Class pases XML with touchXML in an NSMutableArray called listArray.
In the Method grabCountry I can access the listArray and listArray.count works well.

Now I need the listArray.count in another Class the MasterViewController.
But Im getting an EXC_BAD_ACCESS error all the time.
Please help!

Here is the code snipplet:
Parser.h

#import <Foundation/Foundation.h>

@interface Parser : NSObject

@property (strong, retain) NSMutableArray *listArray;
@property (strong, retain) NSURL *url;

-(void) grabCountry:(NSString *)xmlPath;
@end

Parser.m

#import "Parser.h"
#import "TouchXML.h"

@implementation Parser
@synthesize listArray;
@synthesize url;

-(void) grabCountry:(NSString *)xmlPath {

    // Initialize the List MutableArray that we declared in the header
    listArray = [[NSMutableArray alloc] init];  

    // Convert the supplied URL string into a usable URL object
    url = [NSURL URLWithString: xmlPath];

   //XML stuff deleted

    // Add the blogItem to the global blogEntries Array so that the view can access it.
   [listArray addObject:[xmlItem copy]];

  //works fine
  NSLog(@"Amount: %i",listArray.count);
}

 @end

MasterViewController.h

#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "TouchXML.h"
#import "Parser.h"

@class Parser;

    @interface MasterViewController : UITableViewController{

    Parser *theParser;

}
@end

MasterViewControlelr.m

- (void)viewDidLoad
{
NSString *xmlPath = @"http://url/to/xml.xml";

theParser = [[Parser alloc] init];
//Starts the parser
[theParser grabCountry:xmlPath];

//Here I want to access the Array count, but getting an BAD ACCESS error
NSLog(@"Amount %@",[theParser.listArray count]);

[super viewDidLoad];
}

Can anyone explain me what the problem here is?
Thanks!

  • 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-01T17:31:52+00:00Added an answer on June 1, 2026 at 5:31 pm

    Internally, each @property has a corresponding instance variable.

    In your -grabCountry method, you are directly accessing the instance variable in the statement listArray = [[NSMutableArray alloc] init]; (same with url = [NSURL URLWithString: xmlPath];), instead of the @property‘s setter method, causing the NSMutableArray that you alloc-init‘d to not be retained by the property. To invoke the @property‘s setter method, you should call

    NSMutableArray *temp = [[NSMutableArray alloc] init];
    self.listArray = temp; // or [self setListArray:temp];
    [temp release];
    

    If you want to have Xcode show an error when you are directly accessing the instance variable of an @property, you can have @synthesize listArray = _listArray, which changes the name of the instance variable to _listArray.

    Generally, if there is an alloc-init, there must be a corresponding release (except if using Automatic Reference Counting).


    Also, in the [listArray addObject:[xmlItem copy]]; statement, the call to copy is not needed, as NSArrays retain every object that is added to them. Calling copy also increases the retain count, which is another leak. Instead, you should just have [self.listArray addObject:xmlItem];


    You are getting EXC_BAD_ACCESS because in NSLog(@"Amount %@",[theParser.listArray count]);, you are using %@ format specifier, which is for NSStrings. You want to print the array’s count, an integer, so you should be using %d or %i.

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

Sidebar

Related Questions

Iam getting the following error , could some one help me how to fix
Iam getting OutOfMemoryException while making remote method call. RemoteEntity.SetLocalStore(DATASET); passed value is dataset. Note
I am getting crazy over this error. Compiler is saying out of scope for
I am getting an intermittent crash when my application runs on an iPhone. All
In the code below I am getting an EXC_BAD_ACCESS error for no apparent reason
Ok, so I keep getting a EXC_BAD_ACCESS error which I am guessing is alot
I am getting the EXC_BAD_ACCESS error when trying to set a value inside a
I am getting a EXC_BAD_ACCESS (SIGBUS) on this line in my iPhone project: if
I have the following code, from which I am getting an EXC_BAD_ACCESS error: -
i am getting a serious issue Program received signal: EXC_BAD_ACCESS. Data Formatters temporarily unavailable,

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.