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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:12:44+00:00 2026-05-18T09:12:44+00:00

I have a program that i am working on and this is what happen:

  • 0

I have a program that i am working on and this is what happen:

I have a view controller (NewGameViewController) that calls an object. That object reads a .txt file into an array and then do a while loop to populate a Core Data database. I have had problems to populate the database but finally was able to sort that out. However i now get EXC_BAD_ACCESS after return to NewGameViewController.

I have been trying to track down the problem but have not been successful (i am new to this). However i do believe the problem is somewhere in the while loop. I just cannot figure out how to identify the error, or even exactly where it crash.

BTW, it seems like the actual loading of the database works well and just for the record the last .txt record consists of “99999”.

- (void)populateTheDatabase {
NSLog(@"\n \n >>>>> START populateTheDatabase <<<<< \n \n");
NSLog(@">>populateTheDatabase<<");
//
// Init parameters
NSError *error = nil;
int xx = 0;         // Loop number
int eOF;            // Keep track of EOF in array
int keyNumber = 0;
NSString *qNr = [[NSString alloc] init];
int myInt;
//
//=========PREPARE CORE DATA DB===========//
if (managedObjectContext == nil) { managedObjectContext = [(FamQuiz_v2AppDelegate *)
                                                           [[UIApplication sharedApplication] delegate] managedObjectContext]; }
// Define qContext
NSManagedObjectContext *qContext = [self managedObjectContext];
//===============DELETE ALL RECORDS================//
NSLog(@"\n \n Delete all records");
NSFetchRequest * allQzs = [[NSFetchRequest alloc] init];
[allQzs setEntity:[NSEntityDescription entityForName:@"questions" inManagedObjectContext:qContext]];
[allQzs setIncludesPropertyValues:NO]; //only fetch the managedObjectID
//
error = nil;
NSArray * qZs = [qContext executeFetchRequest:allQzs error:&error];
[allQzs release];
//error handling goes here
for (NSManagedObject * rZ in qZs) {
    [qContext deleteObject:rZ];
}
//
//=========COUNT ENTITIES IN DB BEFORE INSERT DATA===========
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity: [NSEntityDescription entityForName: @"questions" inManagedObjectContext: qContext]];
//
error = nil;
NSUInteger countE = [qContext countForFetchRequest: request error: &error];
NSLog(@"#entities in DB before insert: %i", countE);
[request release];
//
//
// Fill myString with questions from the .txt file and then read .txt file
NSString *filePath = @"/Users/PeterK/Documents/FamilyQuiz/FamQuiz_v2_02/loadq101023v2.txt";
NSString *myString = [[NSString alloc] initWithContentsOfFile:filePath];
//
// Load array
NSArray* myArray = [myString componentsSeparatedByString:@"\r"];
//NSLog (@"\n \n Number of elements in myArrayX = %i", [myArrayX count]);
NSLog (@"\n \n Number of elements in myArray = %i", [myArray count]);
//
//NSLog(@"myArray: %@", myArray);
//
while (eOF != 99999) {
    NSLog(@"xx: %i", xx);
    qNr = [myArray objectAtIndex:xx];
    eOF = [qNr intValue];
    //
    if (eOF != 99999) {
        NSManagedObject *famQuizInfo = [NSEntityDescription
                                        insertNewObjectForEntityForName:@"questions" 
                                        inManagedObjectContext:qContext];
        // index = 0 : 'record number'
        [famQuizInfo setValue:[NSNumber numberWithInt:keyNumber] forKey:@"idQ"];
        keyNumber = keyNumber++;
        NSLog(@"nr: %i - myArray 0: %@", xx, [myArray objectAtIndex:xx]);
        xx = xx++;
        // index = 1 : 'difficulties level'
        NSString *myObject1 = [[NSString alloc] init];
        myObject1 = [myArray objectAtIndex:xx];
        myInt = [myObject1 intValue];
        [famQuizInfo setValue:[NSNumber numberWithInt:myInt] forKey:@"qDiff"];
        NSLog(@"nr: %i - myArray 1: %@", xx, [myArray objectAtIndex:xx]);
        xx = xx++;
        [myObject1 release];
        // index = 2 : 'category' not existing in the DB anymore, but exist in the .txt
        NSLog(@"nr: %i - myArray 2: %@", xx, [myArray objectAtIndex:xx]);
        xx = xx++;
        // index = 3 : 'question'
        [famQuizInfo setValue:[myArray objectAtIndex:xx] forKey:@"question"];
        NSLog(@"nr: %i - myArray 3: %@", xx, [myArray objectAtIndex:xx]);
        xx = xx++;
        // index = 4 : 'right answer'
        [famQuizInfo setValue:[myArray objectAtIndex:xx] forKey:@"qRightAnswer"];
        NSLog(@"nr: %i - myArray 4: %@", xx, [myArray objectAtIndex:xx]);
        xx = xx++;
        // index = 5 : 'wrong answer #1'
        [famQuizInfo setValue:[myArray objectAtIndex:xx] forKey:@"qWrongAnswer1"];
        NSLog(@"nr: %i - myArray 5: %@", xx, [myArray objectAtIndex:xx]);
        xx = xx++;
        // index = 6 : 'wrong answer #2'
        [famQuizInfo setValue:[myArray objectAtIndex:xx] forKey:@"qWrongAnswer2"];
        NSLog(@"nr: %i - myArray 6: %@", xx, [myArray objectAtIndex:xx]);
        xx = xx++;
        // placeholder for number of times the question is asked
        [famQuizInfo setValue:[NSNumber numberWithInt:0] forKey:@"qNrAccess"];
        // date when the question was registred
        [famQuizInfo setValue:[NSDate date] forKey:@"qRegDate"];
        //
        NSLog (@"\n ============== \n");
        //
        //
        if (![qContext save:&error]) {
            NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
            error = nil;
            if (![qContext save:&error]) {
                NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
                //
                if(![[famQuizInfo managedObjectContext] save:&error]) {
                    NSLog(@"Failed to save to data store: %@", [error localizedDescription]);
                    NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];
                    if(detailedErrors != nil && [detailedErrors count] > 0) {
                        for(NSError* detailedError in detailedErrors) {
                            NSLog(@"  DetailedError: %@", [detailedError userInfo]);
                        }
                    }
                    else {
                        NSLog(@"  %@", [error userInfo]);
                    }
                }
            }
        }
    }
}
//
//
//=========COUNT ENTITIES IN DB AFTER INSERT DATA===========
NSFetchRequest *request2 = [[NSFetchRequest alloc] init];
[request2 setEntity: [NSEntityDescription entityForName: @"questions" inManagedObjectContext: qContext]];

error = nil;
NSUInteger count2 = [qContext countForFetchRequest: request2 error: &error];
NSLog(@"#entities in DB after insert: %i", count2);
[request2 release];
//
//
[qNr release];

}

  • 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-18T09:12:44+00:00Added an answer on May 18, 2026 at 9:12 am

    If there is a crash, there is a backtrace. Post it.

    Where is the crash happening? You should be able to get a backtrace from the debugger or there should be a crash report available.


    Here is a problem:

     NSString *qNr = [[NSString alloc] init];
     ... later ....
     qNr = [myArray objectAtIndex:xx];
     ... even later ...
     [qNr release];
    

    That is a leak (the assignment without releasing the first string) and a crash (releasing an object that was never retained).

    And another one:

        NSString *myObject1 = [[NSString alloc] init];
        myObject1 = [myArray objectAtIndex:xx];
        ...
        [myObject1 release];
    

    In both cases, neither the alloc/init, nor the release are necessary.


    The memory management guide will likely be quite helpful.

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

Sidebar

Related Questions

I have a program that spits out both standard error and standard out, and
I have a program that creates a Windows user account using the NetUserAdd() API
I have a program that uses the mt19937 random number generator from boost::random. I
I have a program that spits out an Excel workbook in Excel 2003 XML
I have a program that monitors debug messages and I have tried using a
I have a program that will calculate the minimal area taken by fitting rectangles
I have a program that runs osql.exe from microsoft sql server tools directory and
I have a program that I need to run under *nix and windows. because
I have a program that when it starts, opens a winform (it is the
I have a program that can have a lot of parameters (we have over

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.