CRASH: -[NSNull length]: unrecognized selector sent to instance错误的处理办法

开发中从后台请求数据,返回如下:

2014-12-05 16:44:52.535 掌麦[6984:613] getDefaultAddress: reuslt == {

item =     {

data =         {

address = "<null>";

area = "<null>";

city = "<null>";

name = "";

phone = 18503051318;

province = "<null>";

};

mark = 1;

msg = "\U6210\U529f";

};

status = 1;

}

我直接解析出字典dic,赋值:

<span style="font-size:18px;">    NSString *address = [dic objectForKey:@"address"];
    //NSString *area = [dic objectForKey:@"area"];
    NSString *name = [dic objectForKey:@"name"];
    //NSString *city = [dic objectForKey:@"city"];
    NSString *phone = [dic objectForKey:@"phone"];
    //NSString *province = [dic objectForKey:@"province"];
    self.addressLabel.text = address;
    self.nameLabel.text    = name;
    self.phoneLabel.text   = phone;

</span>

结果报错:CRASH: -[NSNull length]: unrecognized selector sent to instance

原因及时后台返回有些值为null,在object-c中就是nsull的空值

所以解析后,应加一判断,防止出错

<span style="font-size:18px;">    if (![address isKindOfClass:[NSNull class]]) {
        self.addressLabel.text = address;
    }
    if (![name isKindOfClass:[NSNull class]]) {
        self.nameLabel.text    = name;
    }
    if (![phone isKindOfClass:[NSNull class]]) {
        self.phoneLabel.text   = phone;
    }
</span>

这样就OK了

时间: 2024-10-29 09:52:46

CRASH: -[NSNull length]: unrecognized selector sent to instance错误的处理办法的相关文章

(未解决)[NSNull intValue]: unrecognized selector sent to instance 0x375c9860

今天遇到这个问题,程序崩溃了……日志如下: -[NSNull intValue]: unrecognized selector sent to instance 0x375c9860*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull intValue]: unrecognized selector sent to instance 0x375c9860' ***

iOS开发&mdash;&mdash;异常:[__NSCFNumber length]: unrecognized selector sent to instance

  *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector sent to instance   网上参考的他人案例,与我的情况一模一样,所以直接盗用他的图和文章了. http://www.tuicool.com/articles/EZ3uMb7         这个错误是作者解析pilst文

[__NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000022

2015-07-28 16:34:24.374 EzPlug[1532:602143] -[__NSCFNumber length]: unrecognized selector sent to instance 0xb0000000000000222015-07-28 16:34:37.367 EzPlug[1532:602143] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reaso

-[__NSCFNumber length]: unrecognized selector sent to instance 0x1657c5c0 2014-09-24 14:47:39.170 St

-[__NSCFNumber length]: unrecognized selector sent to instance 0x1657c5c0 2014-09-24 14:47:39.170 StarShow[1948:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber length]: unrecognized selector se

-[__NSCFNumber length]: unrecognized selector sent to instance 崩溃解决

崩溃原因是由于:获取JSON数据后存放在默认的NSMutableArry里,NSMutableArry是存放id类型的, uiTableViewCellMakeMoneyCustomCell.uiLabelActiveCountPoint.text=[nsMutableArryAllheActivesCountPoints objectAtIndex:indexPath.row]; 使用时引起类型不一致: 转化一下就可以了 uiTableViewCellMakeMoneyCustomCell.u

静态库调用中“unrecognized selector sent to instance”错误

在开发调用静态库的中,出现 “unrecognized selector sent to instance 0x2b5f90”的错误 -[__NSCFConstantString xmlChar]: unrecognized selector sent to instance 0x2b5f90 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantS

[__NSCFNumber length]: unrecognized selector sent to instance 0x8b3c310

出现这种问题一般是你把int类型的数值赋给了NSString. 比如: 你定义了一个NSString类型的属性sex,但是服务端返回的sex字段实际上是NSNumber类型, 你直接把NSNumber类型的值赋给了sex,然后把这个sex赋给了_sexLabel.text,这时就会出现这种错误. 使用Plist文件时遇到这种错误也可以按照这个方法来检查.

[__NSCFConstantString size]: unrecognized selector sent to instance 错误

因为使用时候的类型和初始化的对象类型不匹配造成的,例如 #define TITLE_NAME_nor @[@"hot_c",@"bgyl_c",@"microphone_c",@"socker-ball_c",@"more_c"] [button setImage:TITLE_NAME_nor[i] forState:UIControlStateNormal]; 写代码快了,没注意,直接把名字给付给图片了.

解决因为NSNull类型导致出现的unrecognized selector sent to instance问题

问题描述:因为objc是动态语言,对象的类型在运行时才会被确认,所以很容易出现一个定义为NSString类型的变量,在运行时的类型变成了NSNull,从而导致如下错误出现:-[NSNull stringByAppendingFormat:]: unrecognized selector sent to instance 下面介绍一下解决这个问题的思路 首先我们知道objc提供了消息转发机制,可以挽救当一个类调用了不存在的方法时,给你挽救的机会.我们就可以利用这个机制来拯救这个错误. 我们通过创建