這是我的.m文件中的內容,來自xcode。 我的主要目標是有一個按鈕播放聲音(不是在同一時間),當它有2個聲音文件附加和一個隨機發生器,因此它不會播放兩次相同的聲音或不會做兩次。我運行代碼,當我點擊Yes按鈕時,發生lldb NSEsception錯誤。香港專業教育學院環顧四周的LLDB異常錯誤,但我找到了解決辦法是進入視圖 - 控制器的帶有黃色感嘆號刪除任何東西;它沒有不能解決問題..由於NSEexception而終止?
#import "ViewController.h"
#import <AVFoundation/AVAudioPlayer.h>
@interface ViewController()
@end
@implementation ViewController : UIViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)Yes{
NSMutableArray *array=[NSMutableArray
arrayWithObjects:
@"yes.mp3",
@"yes 3.mp3",
nil];
int i=0;
for(i=0;i<=[array count]; i++)
{
NSInteger rand=(arc4random() %1);
[array exchangeObjectAtIndex:i
withObjectAtIndex:rand];
}
NSString *sound = [array objectAtIndex:i];
AVAudioPlayer* audioPlayer=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:
[[NSBundle mainBundle]pathForResource:sound ofType:@"mp3"]] error:NULL];
[audioPlayer play];
}
@end
http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1 – Paulw11 2014-09-21 22:32:45