【发布时间】:2011-12-26 17:13:33
【问题描述】:
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
当我在我的设备上运行它时,它给了我以下错误:
线程 1:程序接收到的信号:“SIGABRT”。
我该如何解决这个问题?
2011-11-10 14:59:43.487 AVMultiPlayer[13554:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
*** First throw call stack:
(0x3102a8bf 0x381cf1e5 0x3102a7b9 0x3102a7db 0x3803e06f 0x3803e00b 0x2dc9 0x2b5d 0x30f84435 0x32fdf9eb 0x32fdf9a7 0x32fdf985 0x32fdf6f5 0x32fdf321 0x32fde485 0x32fddf01 0x32fc44ed 0x32fc3d2d 0x33bafe13 0x30ffe553 0x30ffe4f5 0x30ffd343 0x30f804dd 0x30f803a5 0x33baefed 0x32ff2743 0x25b5 0x2574)
terminate called throwing an exception(gdb)
这是输出框告诉我的。
【问题讨论】:
-
- (void)playOnce:(NSString *)aSound; - (void)playLooped:(NSString *)aSound; -(IBAction)beatButton1; -(IBAction)switchback:(id)sender;//切换回主页面@end
-
即.h文件代码
-
- (void)dealloc { - (void)playOnce:(NSString )aSound { NSString *path = [[NSBundle mainBundle] pathForResource:aSound ofType:@"caf"]; AVAudioPlayer theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]; [音频setDelegate:self]; [音频 setNumberOfLoops:0]; [音频设置音量:1.0]; [音频播放]; }
-
- (void)playLooped:(NSString )aSound { NSString *path = [[NSBundle mainBundle] pathForResource:aSound ofType:@"caf"]; AVAudioPlayer theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]; [音频setDelegate:self]; // 无限循环 [theAudio setNumberOfLoops:-1]; [音频设置音量:1.0]; [音频播放]; [音频发布]; }
-
设备区分大小写。确保 aSound 中的路径与资源名称完全匹配(错误表示路径参数为 nil)。见stackoverflow.com/questions/4050342/…。
标签: iphone ios4 memory error-handling compiler-errors