Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

lvloh3n

macrumors newbie
Original poster
Oct 16, 2011
13
0
Mashhad, Iran
MOD NOTE: Pulled from: https://forums.macrumors.com/threads/1260798/

I have the same error but in a different situation

I have a text field in my program but when ever I try to type something in it I will get EXC_BAD_ACCESS and the program will crash and the pointer will go to :

int retVal = UIApplicationMain(argc, argv, nil, nil);

what am I doing wrong?
 
Last edited by a moderator:
I think you are going to have to post your code if you are going to get any help with your problem from people here.
 
There is no code for when I click on the text field
or edit it
and main() is the standard main() and I didn't edit it either
I think something must be wrong with my xcode:-?
becaused I used a simple sample program from a book and it did the same thing, ideas?
 
If you ge an error there, means, that there is something wrong somewhere else in your code, the compiler can't cope with the error, and shows you the error in the main. An EXC_BAD_ACCES mostly means you are overreleasing something, or you want to use something that is already released.

You could google for NS ZOMBIEENABLED, and try that for debugging..
 
I think something must be wrong with my xcode:-?

0.1% chance that the problem lies with xcode. It's very much more likely that you and the sample code are doing something wrong. No necessarily the same thing wrong. But if you've based your code on this sample code, then chances are you've replicated the bug.
 
the sample that I used to try the problem is a simple program that only this part of it differ from the original file that xcode will make for you

Code:
@interface HelloXcode4GUIViewController : UIViewController {
    UITextField *txtUsername;
    UILabel *lblOutput;
    
}

@property (nonatomic, retain) IBOutlet UILabel *lblOutput;

@property (nonatomic, retain) IBOutlet UITextField *txtUsername;

@end

Code:
@implementation HelloXcode4_GUIViewController
- (IBAction)btnOK:(id)sender {
    NSString *WelcomeMsg=[[NSString alloc] initWithFormat:@"Welcome to iOS Programming %@",txtUsername.text];
    
    lblOutput.text=WelcomeMsg;
    lblOutput.textColor=[UIColor blueColor];
}

and when I try to change the text field the error will occur, the first sample program in the book and it is not working, why is that?
 
Last edited by a moderator:
first sample program in the book and it is not working, why is that?

In the xib file, do you have a connection between txtUsername and the UITextField object?

What's the output of:
Code:
@implementation HelloXcode4_GUIViewController
- (IBAction)btnOK:(id)sender {
   NSLog(@"In btkOK:, txtUsername is %p", txtUsername);
}
 
In the xib file, do you have a connection between txtUsername and the UITextField object?

What's the output of:
Code:
@implementation HelloXcode4_GUIViewController
- (IBAction)btnOK:(id)sender {
   NSLog(@"In btkOK:, txtUsername is %p", txtUsername);
}

yes the connection is alright

2011-10-24 22:36:40.238 HelloXcode4GUI[569:b303] In btkOK:, txtUsername is 0x4e84e10
 
Here's what I did.

I created a new single-view project in XCode 4.2 on Mac OX 10.7.2 without Storyboards and without Automatic Reference Counting.

I opened the HelloViewController.xib, dragged a text field, button and label into the view. Tweaked some of the properties (but none of the tweaks are essential).

I control+dragged the text field from the view .xib into HelloViewContoller.h and created a new outlet called nameTextField. I did the same with the label to create a new messageLabel outlet.

I control+dragged the button form the view .xib into HelloViewController.h and created a new action called sayHello:.

I then went into HelloViewController.m and added this body to sayHello:.
Code:
- (IBAction)sayHello:(id)sender {
    NSLog(@"In %s", __PRETTY_FUNCTION__);
    
    NSString *name = nameTextField.text;
    NSString *hello =
        [[NSString alloc] 
            initWithFormat:
                @"Welcome to iOS Programming %@",
                name];
    
    messageLabel.textColor = [UIColor blueColor];
    messageLabel.text = hello;
    
    [hello release];
}

It works fine (and fixes a memory leak in your code). Was then anything you did differently?
 
just run it on the iOS simulator 5 and it works prefectly
thank you guys
but still got the error when I choose 4.3, something is wrong with it:D
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.