简单 iPhone 应用程序启动时的 EXC_BAD_ACCESS
背景:
我正在尝试 CS193P 课程中的“HelloPoly”作业。 我创建了 .xib 文件和自定义控制器类。
我没有充实任何方法 - 我只允许 IB 将类文件写入 xcode。
问题:
每次我启动应用程序时,它都会崩溃。当我运行 gdb 时,我看到这是一个 EXC_BAD_ACCESS 错误。这意味着我正在访问内存中不存在的东西,对吧?问题是,我拥有的只是 IB 创建的默认文件和 main.c 文件。而已。
我已经检查了发布的代码解决方案以查看有何不同,但我不确定下一步要尝试什么。当您的应用程序每次启动时崩溃时,你们通常会检查什么?
堆栈跟踪显示它是在创建 UIApplicationMain 时在 main.m 中发生的 - 这意味着我从未将其发送到我的应用程序委托。
这是跟踪:
Program received signal: “EXC_BAD_ACCESS”.
(gdb) where
#0 0x01b70d45 in CFHash ()
#1 0x01b741cf in __CFDictionaryFindBuckets1b ()
#2 0x01b72b0a in CFDictionaryGetValue ()
#3 0x00450535 in -[UIProxyObject initWithCoder:] ()
#4 0x0133886e in UINibDecoderDecodeObjectForValue ()
#5 0x013398c2 in -[UINibDecoder decodeObjectForKey:] ()
#6 0x00450b35 in -[UIRuntimeConnection initWithCoder:] ()
#7 0x0045101c in -[UIRuntimeEventConnection initWithCoder:] ()
#8 0x0133886e in UINibDecoderDecodeObjectForValue ()
#9 0x0133820a in UINibDecoderDecodeObjectForValue ()
#10 0x013398c2 in -[UINibDecoder decodeObjectForKey:] ()
#11 0x0044feab in -[UINib instantiateWithOptions:owner:loadingResourcesFromBundle:] ()
#12 0x00451fcb in -[NSBundle(NSBundleAdditions) loadNibNamed:owner:options:] ()
#13 0x002910a6 in -[UIApplication _loadMainNibFile] ()
#14 0x0029a82a in -[UIApplication _runWithURL:sourceBundleID:] ()
#15 0x00297b88 in -[UIApplication handleEvent:withNewEvent:] ()
#16 0x002936d3 in -[UIApplication sendEvent:] ()
#17 0x0029a0b5 in _UIApplicationHandleEvent ()
#18 0x0239eef1 in PurpleEventCallback ()
#19 0x01bb2b80 in CFRunLoopRunSpecific ()
#20 0x01bb1c48 in CFRunLoopRunInMode ()
#21 0x00291e69 in -[UIApplication _run] ()
#22 0x0029b003 in UIApplicationMain ()
#23 0x000026a8 in main (argc=1, argv=0xbffff000) at main.m:14
我没有在其他线程中看到这个特定问题,但如果我错过了它们,请提示我。
有想法吗?
谢谢。
Background:
I'm trying out the "HelloPoly" assignment in the CS193P course.
I've created my .xib file, and a custom Controller class.
I haven't fleshed out any methods - I've only allowed IB to write the class files into xcode.
Problem:
Every single time I startup the application, it bombs out. When I run gdb I see it's an EXC_BAD_ACCESS error. This means I'm accessing something non-existent in memory right? Thing is, all I have is the default files created by IB and the main. Nothing more.
I've checked posted code solutions to see what's different and I'm not sure what to try next. What do you guys usually check for when your app crashes every time on startup?
The stack trace reveals it's happening in main.m when creating UIApplicationMain - meaning I never make it to my application delegate.
Here's the trace:
Program received signal: “EXC_BAD_ACCESS”.
(gdb) where
#0 0x01b70d45 in CFHash ()
#1 0x01b741cf in __CFDictionaryFindBuckets1b ()
#2 0x01b72b0a in CFDictionaryGetValue ()
#3 0x00450535 in -[UIProxyObject initWithCoder:] ()
#4 0x0133886e in UINibDecoderDecodeObjectForValue ()
#5 0x013398c2 in -[UINibDecoder decodeObjectForKey:] ()
#6 0x00450b35 in -[UIRuntimeConnection initWithCoder:] ()
#7 0x0045101c in -[UIRuntimeEventConnection initWithCoder:] ()
#8 0x0133886e in UINibDecoderDecodeObjectForValue ()
#9 0x0133820a in UINibDecoderDecodeObjectForValue ()
#10 0x013398c2 in -[UINibDecoder decodeObjectForKey:] ()
#11 0x0044feab in -[UINib instantiateWithOptions:owner:loadingResourcesFromBundle:] ()
#12 0x00451fcb in -[NSBundle(NSBundleAdditions) loadNibNamed:owner:options:] ()
#13 0x002910a6 in -[UIApplication _loadMainNibFile] ()
#14 0x0029a82a in -[UIApplication _runWithURL:sourceBundleID:] ()
#15 0x00297b88 in -[UIApplication handleEvent:withNewEvent:] ()
#16 0x002936d3 in -[UIApplication sendEvent:] ()
#17 0x0029a0b5 in _UIApplicationHandleEvent ()
#18 0x0239eef1 in PurpleEventCallback ()
#19 0x01bb2b80 in CFRunLoopRunSpecific ()
#20 0x01bb1c48 in CFRunLoopRunInMode ()
#21 0x00291e69 in -[UIApplication _run] ()
#22 0x0029b003 in UIApplicationMain ()
#23 0x000026a8 in main (argc=1, argv=0xbffff000) at main.m:14
I didn't see this particular problem in other threads, but please clue me in if I missed them.
Ideas?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
NibDecoder 崩溃,即加载 XIB 文件时。您可能在其中引用了不存在或未初始化的对象或属性。
It's crashing in NibDecoder, i.e. when loading your XIB files. You probably have a reference in there to an object or property that doesn't exist or isn't initialized.
检查 .xib 文件的名称和 initByNibName 方法的名称(如果它们相同)。也许,这两个名字是不同的。
Check the name of the .xib file and the name of the initByNibName method, if they are the same. Probably, these two names are different.
我刚刚在一本自学书中为一个类似的基本 iPhone 应用程序解决了这个问题,并意识到我只是在 " 后面而不是前面放错了一个 @ - 喵就是那个搞砸的(如下),这足以抛出错误:
animalSounds=[[NSArray alloc]initWithObjects: @"Oink","@Rawr",@"Ssss",@"Roof","@Meow",@"Honk",@"Squeak", nil];
为了调试,我使用了设置断点和 NSLog 输出的超级基本方法,这样我就可以找出我使用的 4 个变量中的哪一个被搞砸了。
I just solved this for a similarly basic iPhone app in a teach-yourself book, and realized that I had simply misplaced an @ after a " instead of in front - Meow is the one that's messed up (below) and that was enough to throw the error:
animalSounds=[[NSArray alloc]initWithObjects: @"Oink","@Rawr",@"Ssss",@"Roof","@Meow",@"Honk",@"Squeak",nil];
To debug I used the super basic method of setting breakpoints and NSLog output, so I could figure out which of the 4 variables I was using was screwed up.