标签: exc-bad-access

'EXC_BAD_ACCESS'尝试访问变量时?

尝试访问其中设置的函数以外的函数中的变量时,出现" EXC_BAD_ACCESS "错误

该变量在' awakeFromNib '函数中设置:

//Retrieve Session-ID
sessionID = [self getSessionID];
Run Code Online (Sandbox Code Playgroud)

并在' searchBtnClick '中访问:

NSLog(@"Commening search (%@)",sessionID); // This causes the error
Run Code Online (Sandbox Code Playgroud)

变量本身在标题中定义:

NSString *sessionID;
Run Code Online (Sandbox Code Playgroud)

有人可以建议可能出现的问题吗?

getSessionID返回值的部分:

NSString *pC = @"";

// Separate Session ID
pC = [initCookie substringFromIndex:10];
pC = [pC substringToIndex:32];

NSLog(@"Got session ID :  %@",pC);

return pC;
Run Code Online (Sandbox Code Playgroud)

cocoa exc-bad-access objective-c

0
推荐指数
2
解决办法
492
查看次数

iphone EXC_BAD_ACCESS使用我自己的类

我创建了自己的类,由NSObject派生,这是我的代码:

-(void) parseRow:(NSDictionary*) dictionary {
    NSArray* arName = [[dictionary valueForKey:displayname] componentsSeparatedByString:@"+"];
    [self setDriverName:[arName objectAtIndex:0]];
    [self setDriverSurname:[arName objectAtIndex:1]];
    [arName release]; // this give problem!
}
Run Code Online (Sandbox Code Playgroud)

在我看来:

driverStats = [[DriverStats alloc] init];

// driverStats is declared in the header:
DriverStats* driverStats;
@property (nonatomic,retain) DriverStats* driverStats;

[driverStats parseRow:dictionary];
Run Code Online (Sandbox Code Playgroud)

如果我在我的类中添加[arName release],当我从parseRow方法退出时,我有EXC_BAD_ACCESS错误....但是它错了?我使用数组并在我发布之后...我认为错误将是如果我没有释放指针..或不?提前致谢

iphone exc-bad-access class objective-c instance

0
推荐指数
1
解决办法
150
查看次数

EXC_BAD_ACCESS错误,Objective-C问题

嘿,我是Objective-C的新手,还有Cocoa的编程......反正我的代码看起来像:

int main(int argc, char *argv[])
{
printf("how many address would you like to input?\n");
int numAddresses;
scanf("%i", &numAddresses);
char *inputString;

NSMutableArray * arrayOfBooks = [NSMutableArray array];
for (int i = 0; i < numAddresses; ++i) {
 book * f = [[book alloc] init];


 printf("Please input the name of contact %i\n", i+1);
 scanf("%s",inputString);
 [f setName: inputString];

 printf("Please input the address of contact %i\n", i+1);
 scanf("%s", inputString);
 [f setAddress: inputString];

 printf("Please input the birthday of contact %i\n", i+1);
 scanf("%s", inputString);
 [f …
Run Code Online (Sandbox Code Playgroud)

cocoa exc-bad-access objective-c

0
推荐指数
1
解决办法
521
查看次数

自定义代理无法正常工作

在我提出的另一个问题中,我已经开始更多地与代表合作.现在,我已经调用了一个UIViewController ProfileViewController,我希望从Facebook加载News Feed.我也有NSObject的子类调用FBFeed.此子类加载Facebook News Feed并应将其传递回视图控制器.我对Facebook的所有请求都是通过一个名为的单身命令发送的FBRequestWrapper(在这种情况下)应该将结果传递给FBFeed.

我呼吁getFBRequestWithGraphPath:andDelegate:FBRequestWrapper其中将调用Facebook的iOS版SDK的方法,这需要委托作为参数.如果我放入self(这将是FBRequestWrapper)它工作得很好.如果我放入_delegate(这是一个实例FBFeed)应用程序崩溃了EXC_BAD_ACCESS.

我有理论为什么它会崩溃.我读过这个

@property (nonatomic, retain) id <FBFeedDelegate> delegate;
Run Code Online (Sandbox Code Playgroud)

应该

@property (nonatomic, assign) id <FBFeedDelegate> delegate;
Run Code Online (Sandbox Code Playgroud)

但是这样做时我收到以下错误:

对于unsafe_unretained属性'delegate'的现有ivar'委托'必须是__unsafe_unretained

此外,我不知道是否足以使应用程序崩溃.

这是我的代码.

ProfileViewController.h

#import <UIKit/UIKit.h>
#import "FeedTableView.h"
#import "FBFeed.h"

@interface ProfileViewController : UIViewController <FBFeedDelegate>
{
    FeedTableView *tableView;
}

- (void)loadFeed;

@end
Run Code Online (Sandbox Code Playgroud)

ProfileViewController.m

@implementation ProfileViewController

- (void)loadFeed
{
    FBFeed *feed = [[FBFeed alloc] init];
    [feed loadNewsFeedWithDelegate:self];
}

#pragma mark - …
Run Code Online (Sandbox Code Playgroud)

iphone delegates exc-bad-access objective-c retain

0
推荐指数
1
解决办法
6203
查看次数

@autoreleasepool EXC_BAD_ACCESS

我有一个简单的UIViewControler,当我调用方法[self performSelectorInBackground:@selector(load)withObject:nil]; 它导致和EXC_BAD_ACCESS

这是UIViewControler.m和UIViewControler.h

#import <UIKit/UIKit.h>
@interface ViewController : UIViewController

@property (strong, nonatomic) UITextView *myTextView;

@end



#import "ViewController.h"

@implementation ViewController

@synthesize myTextView;

- (id)init {
    self = [super init];
    if (self) {
        myTextView = [[UITextView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        [[self view] addSubview:myTextView];
        [self performSelectorInBackground:@selector(load) withObject:nil];
    }
    return self;
}

- (void) load {
    @autoreleasepool {
        [myTextView setText:@"LOADING ..."];
        //DO SOMETHING ....
    }
}

@end
Run Code Online (Sandbox Code Playgroud)

PS:

该项目使用Objective-C ARC

cocoa-touch exc-bad-access objective-c autorelease

0
推荐指数
1
解决办法
1092
查看次数

animationForKey上的EXC_BAD_ACCESS:

我正在尝试使用Scintilla组件的最新功能,该组件提供类似OSX的文本突出显示效果(黄色动画弹跳框),并且我遇到了间歇性弹出的错误:

EXC_BAD_ACCESS

指向这个特定的行:

if (layerFindIndicator!=nil)
        if ([layerFindIndicator animationForKey:@"animateFound"])
            [layerFindIndicator removeAnimationForKey:@"animateFound"];
Run Code Online (Sandbox Code Playgroud)

(ifs是我的;以防万一我把对象layerFindIndicator弄为零,或者解除分配或其他什么......不幸的是,它没有帮助......)

layerFindIndicator似乎是一个子类CAGradientLayer.(您可能会看到完整的代码layerFindIndicator,在这里).

既然,我是Quartz Core的绝对新手,请给我任何关于如何进行调试的提示?

cocoa exc-bad-access objective-c quartz-graphics cagradientlayer

0
推荐指数
1
解决办法
257
查看次数

C++ EXC_BAD_ACCESS,argv []

我已经坚持了一段时间,无法调试此EXC_BAD_ACCESS错误.我已经运行了NSZombie,我很确定它是一个内存问题argv[1](或者更重要的是).我检查了我的语法和库,所以我不知道为什么它不会存储过去arg[0].

#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

int main(int argc, char* argv[])
{
    cout << "Enter the initial bankroll" << endl;
    int bankroll = atoi(argv[1]); //code faults here

    cout << "Enter seed" << endl;
    int seed = atoi(argv[2]);

    // ...
Run Code Online (Sandbox Code Playgroud)

我遗漏了其余的因为错误发生在其他任何事情之前.

代码在终端中运行但是我的班级的自动分级器失败了.

输入的参数:

./blackjack 400 1

应该适用于任何数字.

argv[0]应该是二十一点,argv[1]第一个数字和argv[2]第二个?

c++ exc-bad-access command-line-arguments

0
推荐指数
1
解决办法
618
查看次数

插入时EXC_BAD_ACCESS

我正在使用FMDatabase来操作sqlite3数据库.这是我的代码:

NSString *dbFilePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"temp_info.db"]];

FMDatabase *fmdb = [FMDatabase databaseWithPath:dbFilePath];
if (![fmdb open]) {
    NSLog(@"......");
} else {
    NSString *sql = @"CREATE TABLE IF NOT EXISTS test1(id INTEGER, name TEXT, create_time TEXT)";
    if (![fmdb executeUpdate:sql]) {
        NSLog(@"......");
    }
    for (int i = 0; i < 3; i++) {
        BOOL result = [fmdb executeUpdate:@"INSERT INTO test1(id, name, create_time) values(?,?,?)", i+1, @"test", @"12-09-10 12:10"];
        NSLog(@"%d", result);
    }
    // EXC_BAD_ACCESS
}
Run Code Online (Sandbox Code Playgroud)

当我运行这条线时:

BOOL result = [fmdb executeUpdate:@"INSERT INTO …
Run Code Online (Sandbox Code Playgroud)

sqlite exc-bad-access insert fmdb

0
推荐指数
1
解决办法
1537
查看次数

带有UIImagePickerControllerSourceTypeCamera的UIImagePickerController在ios7中崩溃EXC_BAD_ACCESS

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = YES;
[self presentViewController:imagePicker animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

此代码使ios7设备上的EXC_BAD_ACCESS崩溃.在iOS6上 - 一切正常,UIImagePickerControllerSourceTypePhotoLibrary工作正常.

exc-bad-access objective-c uiimagepickercontroller ios ios7

0
推荐指数
1
解决办法
2367
查看次数

为什么我得到EXC_BAD_ACCESS?

我想反转一个字符串,但我在swap char上出错了.

有人可以帮我吗?

char*  reverse_char(char* src){
    char *p,*q;
    p = q = src;
    while(*(p) != '\0'){
        p++;
    }
    p--;

    char  temp = '\0';
    while (p > q) {
        temp = *p;
        *p = *q; // I got exec bad access here ??? why 
        *q = temp;
        p--;
        q++;
    }
    return src;
}
Run Code Online (Sandbox Code Playgroud)

这是主要方法.

int main(int argc, char const* argv[])
{
    char *hi = "hello world!\n";
    printf("%s", hi);

    reverse_char(hi);
    printf("%s", hi);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c exc-bad-access

0
推荐指数
1
解决办法
1563
查看次数