【问题标题】:thread 1 program received signal SIGABRT线程 1 程序收到信号 SIGABRT
【发布时间】: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


【解决方案1】:

在你使用的代码中的某个地方

[NSURL initFileURLWithPath:]

但是你传递了一个 nil 路径值。
检查你的字符串。

【讨论】:

  • - (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]; [音频播放];
  • 那是我四个有[NSURL initFileURLWithPath:]的代码
【解决方案2】:

您的路径在设备上为零。

首先,尝试清理您的项目。

然后,确保在“复制捆绑资源”构建阶段复制文件

正如 Anna Karenina 建议的那样,确保以区分大小写的方式处理名称。

【讨论】:

  • 你的第二点对我有用。出于某种原因,当我将 CAF 文件拖到我的项目中时,它没有将它们放入“复制包资源”中
【解决方案3】:
- (void)playOnce:(NSString )aSound {    // <-- Write NSString* here. Check it, it may be null

    // or "aSound".caf is not include in your project or is just not checked to be part of your project (remove it and add it again)
    NSString *path = [[NSBundle mainBundle] pathForResource:aSound ofType:@"caf"];
    AVAudioPlayer theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]; 

   [theAudio setDelegate: self]; 
   [theAudio setNumberOfLoops:0]; 
   [theAudio setVolume:1.0]; 
   [theAudio play];
}

【讨论】:

  • - (void)playOnce:(NSString *)aSound; - (void)playLooped:(NSString *)aSound;
  • 我必须添加什么来修复这个程序
  • @alfred :我的回答中有评论
  • @alfred:添加文件时,是否选中了表示您的文件包含在您的项目中的复选框?
  • @alfred:调试时,NSString 是 nil,aSond 还是 path ?
【解决方案4】:

重要的错误是'NSInvalidArgumentException',正如错误所说,问题是其中一个字符串是不应该的空值。根据您的尝试,这篇文章可能会有所帮助:Proper use of UIApplicationMain

【讨论】:

  • 我只是想让按钮播放声音
猜你喜欢
  • 1970-01-01
  • 2012-01-08
  • 1970-01-01
  • 1970-01-01
  • 2011-09-11
  • 1970-01-01
相关资源
最近更新 更多