title: ToggleButton code in Android Studio unexpectedly crashes the App
body: <p>My project is a music player that has a ToggleButton for play/pause.</p>
  
  <p>I tried to run a code in Android Studio, but it unexpectedly crashes the App. </p>
  
  <p>I am trying to follow up some tutorials on the internet and YouTube guides, but nothing works so far.</p>
  
  <p>Here is the code that I'm running in the MainActivity:</p>
  
  <pre><code>package com.example.hamzeh.playpausestop;
  
  import android.media.MediaPlayer;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.ToggleButton;
  
  public class MainActivity extends AppCompatActivity {
  
      MediaPlayer Sound;
      int pause;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
  
      public void stop(View view)
      {
          Sound.release();
      }
  
      public void onToggleClicked(View view)
      {
          boolean checked = ((ToggleButton)view).isChecked();
  
          if (checked)
          {
              Sound.start();
              //Play
          }
          else
          {
              Sound.pause();
              pause = Sound.getCurrentPosition();
              //Pause
          }
  
      }
  
  }
  </code></pre>