EXC_BAD_ACCESS on UIApplicationMain

Discussion in 'iOS Programming' started by lvloh3n, Oct 23, 2011.

  1. lvloh3n, Oct 23, 2011
    Last edited by a moderator: Oct 23, 2011

    lvloh3n macrumors newbie

    lvloh3n

    Joined:
    Oct 16, 2011
    Location:
    Mashhad, Iran
    #1
    MOD NOTE: Pulled from: http://forums.macrumors.com/showthread.php?t=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?
     
  2. larswik macrumors 68000

    Joined:
    Sep 8, 2006
    #2
    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.
     
  3. lvloh3n thread starter macrumors newbie

    lvloh3n

    Joined:
    Oct 16, 2011
    Location:
    Mashhad, Iran
    #3
    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?
     
  4. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    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..
     
  5. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #5
    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.
     
  6. lvloh3n, Oct 24, 2011
    Last edited by a moderator: Oct 24, 2011

    lvloh3n thread starter macrumors newbie

    lvloh3n

    Joined:
    Oct 16, 2011
    Location:
    Mashhad, Iran
    #6
    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?
     
  7. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #7
    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);
    }
    
     
  8. lvloh3n thread starter macrumors newbie

    lvloh3n

    Joined:
    Oct 16, 2011
    Location:
    Mashhad, Iran
    #8
    yes the connection is alright

    2011-10-24 22:36:40.238 HelloXcode4GUI[569:b303] In btkOK:, txtUsername is 0x4e84e10
     
  9. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #9
    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?
     
  10. lvloh3n, Oct 25, 2011
    Last edited: Oct 25, 2011

    lvloh3n thread starter macrumors newbie

    lvloh3n

    Joined:
    Oct 16, 2011
    Location:
    Mashhad, Iran
    #10
    nope it is all the same
    how can I send you the sample program that has the error?

    Edit: you can download the sample code for the book I am using from here
    http://www.packtpub.com/support?nid=8069
    the sample program that has the error is in chapter 3/HelloXcode4_GUI
     
  11. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #11
    That sample code worked worked. What versions of XCode and Mac OS X are you using?
     
  12. lvloh3n thread starter macrumors newbie

    lvloh3n

    Joined:
    Oct 16, 2011
    Location:
    Mashhad, Iran
  13. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #13
    I couldn't reproduce the error after dropping down to iOS simulator 4.3. Can you upgrade to XCode 4.2?
     
  14. lvloh3n thread starter macrumors newbie

    lvloh3n

    Joined:
    Oct 16, 2011
    Location:
    Mashhad, Iran
    #14
    ok will do
    gonna upgrade to xcode 4.2 and iOS simulator 5 and will get back to you
     
  15. lvloh3n thread starter macrumors newbie

    lvloh3n

    Joined:
    Oct 16, 2011
    Location:
    Mashhad, Iran
    #15
    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
     

Share This Page