如何解决线程错误EXC_BAD_ACCESS?

时间:2012-10-19 07:04:52

标签: iphone objective-c ios xcode ios5

我想修复线程1的错误EXC_BAD_ACCESS(代码= 2,地址= 0x30)当我点击按钮时出现此错误,按钮代码如下所示

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    DBHandler *db = [[DBHandler alloc]init];

    word_id = [[NSString alloc]init];

    NSLog(@"String %@",word_id);

    [db addFavoriteWord:word_id];
    // Do any additional setup after loading the view from its nib.

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)nextView:(id)sender {
}

@end

1 个答案:

答案 0 :(得分:1)

尝试更改代码:

word_id = [[NSString alloc]init];  

word_id = [NSString stringWithString:@""];