2016-08-01 35 views
0

我是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() 



    } 
} 
+1

嘗試從var audioPlayer = AVAudioPlayer()行刪除制動點。你可以意外設置它。 –

+0

謝謝,但現在模擬器只是空白,錯誤仍然存​​在... – lemontree

回答

0

首先,你會在某個應用程序看到一個斷點。點擊它,然後只需按下鍵盤上的刪除按鈕。這應該可以解決您的問題。

Image1

+0

讓我知道如果這有幫助,請。 –

+0

如果它**沒有工作,請確保您的應用程序有一個入口點,在'故事板'(因爲你說模擬器變爲空白)。如果沒有,轉到第一個'ViewController',到**屬性檢查器**,並檢查:'是初始視圖控制器' –

+0

謝謝,但我的代碼中沒有斷點,第一個入口點屏幕。還有其他解決方案嗎?謝謝! – lemontree