objective-c EXC_BAD_access code=2 地址 0x8
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18952954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
EXC_BAD_access code=2 address 0x8
提问by hossein1448
I have an app that I've been working on, which worked perfectly on iOS 6 in XCode 4.5, but now I downloaded XCode 5 with iOS 7 and get this error,
我有一个我一直在开发的应用程序,它在 XCode 4.5 的 iOS 6 上运行良好,但现在我用 iOS 7 下载了 XCode 5 并收到此错误,
Thread 1: EXC_BAD_access code=2 address 0x8
线程 1:EXC_BAD_access 代码=2 地址 0x8
in main.m :
在 main.m 中:
#import <UIKit/UIKit.h>
#import "TestAppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([TestAppDelegate class]));
}
}
I downloaded iOS 6 sdk and the code work perfect on iOS 6 sdk yetbut with iOS 7 , i get this error , and I don't know why?
I try to debug this but get no information about the crash. I read something about zombies and enabled it by going to Product->Edit Schema->Diagnostic->Enable Zombie Object. But even after this I didn't get anything helpful.
我下载了 iOS 6 sdk 并且代码在 iOS 6 sdk 上完美运行,yet但是在 iOS 7 上,我收到此错误,我不知道为什么?我尝试对此进行调试,但未获得有关崩溃的信息。我阅读了一些关于僵尸的内容,并通过转到Product->Edit Schema->Diagnostic->Enable Zombie Object启用它。但即使在这之后我也没有得到任何帮助。
Any pointers?
任何指针?
采纳答案by Faisal Memon
I'd like to expand on the tip given by Vinzzz but differing slightly (exception not symbolic breakpoint).
我想扩展 Vinzzz 给出的提示,但略有不同(例外不是符号断点)。
The problem here is that the program has stopping on an OS caught exception (bad access). You need to go one step earlier than this, to see the exception in code which would lead to an iOS exception. Go to the breakpoints tab on the left Xcode screen panel section (Breakpoint Navigator). Then at the bottom of the panel there should be a + sign. Click there and add an 'Exception Breakpoint'. Re-run your program and you should now be breakpointed when the problem is attempted to be introduced into the OS environment. This gives information about who and what is the cause.
这里的问题是程序在操作系统捕获的异常(错误访问)上停止。您需要提前一步,以查看代码中会导致 iOS 异常的异常。转到左侧 Xcode 屏幕面板部分(断点导航器)上的断点选项卡。然后在面板底部应该有一个+号。单击此处并添加“异常断点”。重新运行您的程序,现在应该在尝试将问题引入操作系统环境时设置断点。这提供了有关原因和原因的信息。
回答by Akbar
I had this error too because in my user model class I had an extra object I declared as
我也有这个错误,因为在我的用户模型类中,我有一个额外的对象,我声明为
var image = UIImage()
I didn't use it for that task I took it off from model class, my app didn't crashed I would check model class.
我没有将它用于我从模型类中取下的任务,我的应用程序没有崩溃我会检查模型类。
回答by Tommie C.
When you get to the (lldb) prompt try to hit the continue button. That may reveal the underlying error message in the top of the debugger console. Look for the top of the bold text to see what possible object is causing the problem. This type of error usually refers to an attempt to access an object that has been deallocated.
当您到达 (lldb) 提示时,请尝试点击继续按钮。这可能会在调试器控制台的顶部显示潜在的错误消息。查找粗体文本的顶部以查看导致问题的可能对象。这种类型的错误通常是指尝试访问已解除分配的对象。

