EXC_BAD_ACCESS error occured when using stringWithFormat

this is my header section:

@interface RootViewController : UIViewController
    NSString *status_id;

in the controller file, i am assigning the variable:

- (void)updateStatus
    NSURL *url = [NSURL URLWithString:@"http://localhost/RightNow/API/status.json"];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request startSynchronous];
    NSError *error = [request error];
    NSString *response = [NSString alloc];

    NSError *error2;
    NSData* data = [response dataUsingEncoding:NSUTF8StringEncoding];
    NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:data      options:kNilOptions error:&error2];
    status_id = [json objectForKey:@"id"];

now, when i try to use the status_id again, i get the error

- (IBAction)likeClick:(id)sender
    NSURL *url = [NSURL URLWithString:@"http://localhost/RightNow/API/vote"];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
    [request setRequestMethod:@"POST"];
    [request setPostValue:status_id forKey:@"id"]; //The error comes here
    [request setPostValue:@"like" forKey:@"vote"];
    [request startSynchronous];

sorry about my bad english. please help me, thank you!


[json objectForKey:@"id"]; will return the object in autorelease pool. You either need to send a copy message to it like

status_id = [[json objectForKey:@"id"] copy];

and release it when appropriate (if not using ARC)

Need Your Help

Unbinding events on scrollout - recommended?

jquery backbone.js marionette backbone-views backbone-events

my site is built on backbone. It has a feed based UI, which means there are often a large amount of content displayed in a feed. Roughly, about 30 events bind to each item.

Z-Index Layering issues where content is above the navigational dropdown

javascript jquery html css drop-down-menu

I'm working on some HTML/CSS/JQuery to create a nice design, i have been working on some CSS dropdown navigational items yet the body content seems to be playing itself right on top of my dropdown ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.