【发布时间】:2012-09-18 10:53:03
【问题描述】:
我是 XCode 和 Objective-C 的新手。当我让应用程序在模拟器中运行时,我弹出了这个异常。在 iPad 上它工作正常。分配 AVaudioPlayer 后,我会停止并发出警告 SIGSTOP。
有人有什么建议吗?这是一个严重的例外吗?提前致谢!
我不知道在哪里可以找到“堆栈跟踪”,所以我将 RUN 调试器放到 gdb 中:
来自这里的信息:
挂起的断点 1 - ""soundScape.m":112" 已解决
rndmitem
金额
网址
SIGSTOP 之前的行是:
libc++abi.dylib`__cxa_throw:
0x46e4a44: pushl %ebp
0x46e4a45: movl %esp, %ebp
当前语言:自动;当前目标-c
0x1 似乎没有指向有效的对象。
0x2 似乎没有指向有效的对象。
文件://localhost/Users/myName/Library/Application%20Support/iPhone%20Simulator/5.1/Applications/E92E5F03-0B07-4AF0-BFB4-E1F7009A4E78/babyschets.app/02Seawash.mp3
[切换到进程81163线程0x1720b]
[切换到进程81163线程0x15803]
在异常状态寄存器下:
trapno = (unsigned int) 0x000003
错误=(无符号整数)0x000000
faultvaddr = (unsigned int) 0x087df732
例如,当值如下时会发生这种情况:
随机项:
(NSUInteger) $0 = 1 [没有可用的 Objective-C 描述]
amountOfAudioFiles :
(int) $1 = 2 [没有可用的 Objective-C 描述]
url :
(NSURL *) $2 = 0x07485860
file://localhost/Users/myName/Library/Application%20Support/iPhone%20Simulator/5.1/Applications/E92E5F03-0B07-4AF0-BFB4-E1F7009A4E78/babyschets.app/02Seawash。 mp3
audioFiles1:
(NSArray *) $4 = 0x0747d720 <__nsarrayi>(
01Seawash.mp3,
02海洗.mp3
)
int amountOfAudioFiles = [audioFiles1 count];
NSUInteger randomItem = arc4random()%(int)amountOfAudioFiles;
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:[NSString stringWithString:[audioFiles1 objectAtIndex:randomItem]]
ofType:nil]];
NSError *error;
audioPlayer1 = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
好的,我已经清理了这段代码,这是我的解决方案。现在它像魅力一样运行:
在 .h 文件中: @property (nonatomic, 保留) AVAudioPlayer *audioPlayer1;
在 .m 文件中:
int amountOfAudioFiles = [audioFiles1 count];
int randomItem = (int)(arc4random()%amountOfAudioFiles);
if (randomItem < 0) randomItem = 0;
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:[NSString stringWithFormat:@"%@", [audioFiles1 objectAtIndex:randomItem]]
ofType:nil]];
if (audioPlayer1) {
if (audioPlayer1.isPlaying) {
[audioPlayer1 stop];
audioPlayer1 = nil;
}
} else {
audioPlayer1 = [AVAudioPlayer alloc];
}
NSError *error;
audioPlayer1 = [audioPlayer1 initWithContentsOfURL:url error:NULL];
【问题讨论】:
-
当您的应用程序在 XCode 中崩溃时,通常调试器/控制台会向您显示包含错误详细信息的堆栈跟踪。有什么可以给我们看的吗?
-
SIGSTOP是一个不寻常的信号 - 通常用于终端中的作业控制(即Ctrl-Z和后来的fg)!
标签: objective-c exception avaudioplayer