MarkP
MarkP

Reputation: 2566

Objective-C EXC_BAD_ACCESS on run

I'm creating a basic command line application using this tutorial: http://www.raywenderlich.com/40293/learn-to-code-ios-apps-2-strings-arrays-objects-and-classes

I'm at the stage where it is asks me to type in:

NSLog(@"You entered the word '%@' and it is %li characters long", inputString, [inputString length]);

When I do that, run the app and type in a word in the console window it says I should get

Please enter a word.
objects
You entered the word 'objects' and it is 7 characters long

Which does happen, but then the screen automatically switches to:

xcode error

the error on the green bar says:

 Thread 1: EXC_BAD_ACCESS (code=13, address=0x0)

Can someone explain this?

Upvotes: 0

Views: 93

Answers (2)

Vincent Gable
Vincent Gable

Reputation: 3463

Run the Zombies instrument in Instruments. The crash is caused by releasing an invalid "object". Probably this is because the object was over-released. The Zombies instrument will tell you more about over-release problems.

Upvotes: 3

Michael Dautermann
Michael Dautermann

Reputation: 89549

There's nothing wrong with that line of code.

What's likely happening is that you have nothing after that line of code, and those lines you typed in need to live between the brackets in this template:

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{
    @autoreleasepool {
         // your code goes HERE
    }
    return 0;
}

Upvotes: 0

Related Questions