objective-c 线程 1:EXC_BAD_ACCESS(代码=1,地址=0xf00000c)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19183555/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 21:04:29  来源:igfitidea点击:

Thread 1: EXC_BAD_ACCESS (code=1, address=0xf00000c)

iphoneobjective-cios7xcode5

提问by user2375706

I have problem with Thread 1: EXC_BAD_ACCESS (code=1, address=0xf00000c) and I don't know how to resolve it. It appeared when I change some object in core date and save it and I try to pop this controller to parent. This error is in main() with retVal. here is some code

我的线程 1: EXC_BAD_ACCESS (code=1, address=0xf00000c) 有问题,我不知道如何解决。当我更改核心日期中的某个对象并保存它并尝试将此控制器弹出给父级时,它就会出现。这个错误在 main() 和 retVal 中。这是一些代码

        int retVal;
    @try {
        retVal =  UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
           */\ error is here**
    }
    @catch (NSException *exception) {
        NSLog(@"%@", [exception callStackSymbols]);
        @throw exception;
    }
    return retVal;

After re-runing app all my changes are in core data. What is more this problem is only on iOS 7. iOS 6.1 is ok.

重新运行应用程序后,我的所有更改都在核心数据中。更重要的是这个问题只在 iOS 7 上。iOS 6.1 没问题。

Does someone have idea how to resolve it?

有人知道如何解决吗?

采纳答案by Peter DeWeese

As a comment said this error is likely to be deep in your code. If the culprit is a zombie, the easiest way to find it is to run it (preferably in the latest Xcode, currently Xcode 5, as it has been improved) in profiler and choose "Zombies". When it fails, you can see the history of everything that has happened to the object.

正如评论所说,此错误可能在您的代码中很深。如果罪魁祸首是僵尸,找到它的最简单方法是在分析器中运行它(最好在最新的 Xcode 中,目前是 Xcode 5,因为它已得到改进)并选择“Zombies”。当它失败时,您可以看到对象发生的所有事情的历史。

Also, set an exception breakpoint. You may get a break when the error happens instead of in main, where the exception gets passed up.

另外,设置一个异常断点。当错误发生而不是在 main 中发生时,您可能会中断,在那里异常被传递。

回答by user2375706

I resolved this problem with "Zombies" and the problem was with [UIScrollView(UIScrollViewInternal) _notifyDidScroll]

我用“僵尸”解决了这个问题,问题出在 [UIScrollView(UIScrollViewInternal) _notifyDidScroll]

I added

我加了

- (void)dealloc {

  self.tableView.delegate = nil;

} 

This problem was only in iOS 7.

这个问题只出现在 iOS 7 中。

Thanks for help!

感谢帮助!

回答by KTPATEL

I have resolve this issue only by debugging the source code and re-analyze my logic.

我只能通过调试源代码并重新分析我的逻辑来解决这个问题。

Below are some reference that help me lot.

以下是一些对我有很大帮助的参考。

EXC_BAD_ACCESS means that message was sent to a point in the memory where there's no instance of a class to execute it. Thus “bad access”.

EXC_BAD_ACCESS 意味着消息被发送到内存中没有类的实例来执行它的点。因此,“访问不良”。

You will get EXC_BAD_ACCESS in 3 cases:

您将在 3 种情况下获得 EXC_BAD_ACCESS:

  • An object is not initialized
  • An object is already released
  • Something else that is not very likely to happen
  • 对象未初始化
  • 一个对象已经被释放
  • 其他不太可能发生的事情

That's already a good starting point. Start using the debugger, if you recently added a new object to the class you're working on, put a breakpoint at the line before the freshly added object is used for the first time and check the values in the debugger.

这已经是一个很好的起点。开始使用调试器,如果您最近向正在处理的类添加了一个新对象,请在第一次使用新添加的对象之前在该行放置一个断点并检查调试器中的值。

What's happening most though is that you will be sending a message to an overreleased object – i.e. object that is gone from the call stack. In this cases everything (and indeed everything) you will get in the console will be just :EXC_BAD_ACCESS

但最常发生的情况是,您将向过度释放的对象发送消息——即从调用堆栈中消失的对象。在这种情况下,您将在控制台中获得的所有内容(甚至所有内容)都只是 :EXC_BAD_ACCESS

This is because the object is gone, there is no information what class was it, or what source file or anything else.

这是因为对象消失了,没有信息它是什么类,或者是什么源文件或其他任何东西。

Please try to avoid using zombies for this.

请尽量避免为此使用僵尸。

回答by KTPATEL

EXC_BAD_ACCESS means there is no instance of a class to execute it.

EXC_BAD_ACCESS 意味着没有类的实例来执行它。

There are 2 or more possibilities:

有2种或更多的可能性:

  1. An object is not initialized
  2. An object is already released
  1. 对象未初始化
  2. 一个对象已经被释放

Please debug application carefully and analyze each object carefully. That might solve your issue.

请仔细调试应用程序并仔细分析每个对象。那可能会解决您的问题。

回答by Nay

In my case, I was using third-party library and I forgot to set custom-class name in Storyboard Identity Inspector

就我而言,我使用的是第三方库,但忘记在 Storyboard Identity Inspector 中设置自定义类名称

回答by Superlative

I just had the exact same problem.

我只是遇到了完全相同的问题。

Looked here and found nothing so I started backtracking until I thought, maybe I should try Clean Build Folder

看这里并没有发现什么所以我开始回溯直到我想,也许我应该尝试 Clean Build Folder

I was glad it was as easy as CLEAN BUILD FOLDER!!!

我很高兴它像 CLEAN BUILD FOLDER 一样简单!!!

Product- Clean Build Folder(? ? K)

产品 - 清理构建文件夹(??K)

回答by Stan

I solved the same problem by finding out that the name of one of my NSString variables had the same name as one of the frameworks' class variables. Took seconds to change the name a little and problem disappeared.

我发现我的 NSString 变量之一的名称与框架的类变量之一具有相同的名称,从而解决了同样的问题。花了几秒钟时间稍微更改名称,问题就消失了。

With such a huge number of class variables in frameworks, it is very likely that once in a while, every programmer just by coincidence names some variable in his class exactly the same as one used somewhere in framework classes. So it doesn't have to be Xcode bug in most cases.

框架中有如此大量的类变量,很有可能偶尔,每个程序员只是巧合地将他的类中的某个变量命名为与框架类中某处使用的完全相同的变量。所以在大多数情况下它不一定是 Xcode 错误。

回答by AOY

And there may be another issue which I faced today: I had a mutable dictionary with a non-object entry try. There was a code snippet with adding a BOOL value to the dictionary. So no wonder that I got this error =).

可能还有我今天面临的另一个问题:我有一个带有非对象条目尝试的可变字典。有一个向字典添加 BOOL 值的代码片段。所以难怪我得到这个错误 =)。