如何读取“无法识别的选择器” obj-c / iPhone 应用程序中的错误日志
我的应用程序中出现以下崩溃日志错误:
-[NSNull length]: unrecognized selector sent to instance 0x194adc8
我该如何阅读?这是否意味着:
- 我向“
NSNull
”对象发送了“length”消息? - 尝试调用另一个类上的选择器时,“
NSNull
”类中的“length”方法崩溃了?
另外,如果是前一个选项,我如何获取堆栈跟踪以查看哪个函数导致了此崩溃?最上面一行是我日志中唯一的错误。
谢谢
i've got the following crash log error in my app:
-[NSNull length]: unrecognized selector sent to instance 0x194adc8
How do i read this? Does it mean that:
- I sent a 'length' message to a '
NSNull
' object? - The 'length' method in the '
NSNull
' class crashed when trying to call a selector on another class?
Also, if it is the former option, how can i get the stack trace to see which function caused this crash? That top line is the only error in my log.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Door 1
NSNull
不响应length
您可以查看 NSNull 看到是这样的。
如果不知道您的代码库在做什么,我不知道该去哪里查找,您必须在某个时刻调用
[NSNull null];
来获取NSNull
对象或者您正在某个地方使用返回此值的框架。Door 1
NSNull
does not respond tolength
You can check the documentation for NSNull to see that this is the case.
Without having an idea of what your code base is doing I am not sure where to look, you must be calling
[NSNull null];
at some point to get theNSNull
object or you are using a framework somewhere that returns this.这意味着您将“length”发送给 NSNull,而 NSNull 没有“length”函数。
打开 NSZombies 可能会对您有所帮助(它会保留已释放的对象,以便它可以告诉您尝试访问哪个对象),但我认为在这种情况下,您可能会在某个时刻将对象设置为 NSNull (或者它是从函数返回的)。
无论如何,要打开 NSZombies,请转到“项目”>“NSZombies”。编辑活动可执行文件>参数选项卡 >然后添加一个名为 NSZombieEnabled 的变量并将值设置为 YES。确保完成后将其关闭,因为它可能会导致内存问题。
It means you sent 'length' to NSNull and NSNull doesn't have a 'length' function.
Turning on NSZombies might help you (it keeps deallocated objects around so it can tell you which object you tried to access) but I think in this case you probably set an object to NSNull at some point (or it was returned from a function).
Anyway to turn on NSZombies, go to Project > Edit Active Executable > Arguments tab > Then add a variable called NSZombieEnabled and set the value to YES. Make sure you turn it off when you're done though because it can cause memory issues.
这意味着您正在使用 Length 方法来计算字符串长度,
例如
If([strText 长度]>0)
{
//在这里做点什么----
}
别的
{
//在这里做一些事情--
所以
在上面的情况下 - strText 是 NSNull 那么肯定会发生崩溃并且 GDB 将显示如下消息:
[NSNull length]:无法识别的选择器发送到实例
如上所述,Null 没有 Length 方法。
用于救援:
首先检查:
if ((NSNull *)strText == [NSNull null])
{
返回 strText=@"";
}
这将防止 NSNULL 崩溃
It means that you are using a Length method for calculating the string length
Like
If([strText Length]>0)
{
//do something here----
}
else
{
//Do somethig here--
}
So in above case- strText is NSNull then definitely a crash will accure and GDB will show a message like:
[NSNull length]: unrecognized selector sent to instance
As above told already Null don't have Length method.
For rescue:
check first:
if ((NSNull *)strText == [NSNull null])
{
return strText=@"";
}
This will prevent for crash for NSNULL