简体   繁体   中英

Program received signal: “EXC_BAD_ACCESS”

I have a string variable which stores date from date picker but when I use its value in other function I am getting error like Program received signal: “EXC_BAD_ACCESS”. Note: variable is globally defined.

code :

    - (void) changedDate: (UIDatePicker *) picker 
    {
     if (appDelegate.dateint == 8)
     {
     NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; 

[dateFormatter setDateFormat:@"dd MMM, yyyy"];
     datestr=[dateFormatter stringFromDate:[dptpicker date]]; 
    NSLog(@"date:%@",datestr); 
    } 
    else if(appDelegate.dateint == 9) 
    { NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; 

[dateFormatter setDateFormat:@"dd MMM, yyyy"]; 
    datestr1=[dateFormatter stringFromDate:[dptpicker date]] ;
     NSLog(@"date1:%@",datestr1);
     } 
    }

You have to retain that string. This is the most likely reason.

Edit: The only reason why it is crashing is the bad pointer. The bad pointer = over-releasing the object. Just run your app with zombies enabled and you'll see the place where you're doing that. Check this http://www.markj.net/iphone-memory-debug-nszombie/

Whenever there is a crash, post the backtrace.

Before you do, use "build and analyze" and fix any problems it identifies.

After doing that, if it still crashes, then do a pass with Zombie detection on and see if you are over-releasing something (which is likely, that code has an obvious over-release problem as is).

If it is still crashing, then we'll need to see more code....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM