title: Play sound in a fragment
body: <p>I want to press an image button and it should play an mp3 file in raw.</p>
  
  <p>Here is my code and error in it - </p>
  
  <pre><code>public class Fragment_food_apple extends Fragment{
  
      MediaPlayer MediaPlayer;
      ImageButton btn;
      public Fragment_food_apple() {
  
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          final MediaPlayer mp = MediaPlayer.create (this, R.raw.apple);
          //////problem is in up line and it is under this,
          btn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  mp.start();
              }
          });
  
      };
  </code></pre>