title: Swift Error: Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
body: <p>I am getting this problem in my code:</p>
  
  <pre><code>Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
  </code></pre>
  
  <p>This message appears on this line of my code:</p>
  
  <pre><code>try player = AVAudioPlayer(contentsOf: URL(fileURLWithPath: fileLocation!))
  </code></pre>
  
  <p>Any help would be greatly appreciated. Thanks in advance!</p>
  
  <pre><code>import UIKit
  import AVFoundation
  
  class ViewController: UIViewController {
  
      var player = AVAudioPlayer()
  
      override func viewDidLoad() {
          super.viewDidLoad()
          // Do any additional setup after loading the view, typically from a nib.
      }
  
      override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
  
          if event?.subtype == UIEvent.EventSubtype.motionShake {
  
              let fileLocation = Bundle.main.path(forResource: "sound1", ofType: "mp3")
  
              do {
                  try player = AVAudioPlayer(contentsOf: URL(fileURLWithPath: fileLocation!))
                  player.play()
              } catch {
                  // process error   
              }   
          }   
      }
  }
  </code></pre>