我是Swift的初學者,目前我正在爲一個學校項目構建一個應用程序。當我想測試我的應用程序,它說「構建成功」但隨後突然倒閉,和ViewController.swift屏幕上它與該錯誤的綠線:我在網上搜索「線程1:斷點3.5」錯誤
'Thread 1: breakpoint 3.5'
爲任何可能的答案,但我找不到任何。有人能幫助我嗎?謝謝!
更新:現在有一個錯誤說'線程1:EXC_BAD_INSTRUCTION(代碼= EXC_I386_INVOP,子代碼= 0x0)'。我搜索了,我不知道如何解決這個...任何人?
下面是代碼:
的都去斷點導航儀,如(1)所示,然後鏈接的圖片描述import UIKit
import AVFoundation
class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate
{
@IBOutlet weak var pickerView: UIPickerView!
var pickerDataSource = ["White", "Red", "Green", "Blue"];
override func viewDidLoad() {
super.viewDidLoad()
self.pickerView.dataSource = self;
self.pickerView.delegate = self;
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerDataSource.count;
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
return pickerDataSource[row]
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
if(row == 0)
{
self.view.backgroundColor = UIColor.whiteColor();
}
else if(row == 1)
{
self.view.backgroundColor = UIColor.redColor();
}
else if(row == 2)
{
self.view.backgroundColor = UIColor.greenColor();
}
else
{
self.view.backgroundColor = UIColor.blueColor();
}
};
var audioPlayer = AVAudioPlayer() // This is where the error occurs
@IBAction func PlaySound(sender: UISwipeGestureRecognizer) {
// Set the sound file name & extension
let alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("woosh", ofType: "mp3")!)
do {
// Preperation
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
} catch _ {
}
do {
try AVAudioSession.sharedInstance().setActive(true)
} catch _ {
}
// Play the sound
do {
audioPlayer = try AVAudioPlayer(contentsOfURL: alertSound)
} catch _{
}
audioPlayer.prepareToPlay()
audioPlayer.play()
}
}
嘗試從var audioPlayer = AVAudioPlayer()行刪除制動點。你可以意外設置它。 –
謝謝,但現在模擬器只是空白,錯誤仍然存在... – lemontree