title: Android Studio Play & Record Audio Errors. 'Cannot Resolve Sybmol' And 'Cannot Resolve method '
body: <p>I'm Trying to Build an Application that can Record and Play Audio and i found <a href="https://developer.android.com/guide/topics/media/mediarecorder#java" rel="nofollow noreferrer">An Android Studio Developer Website</a>  That Tells me how to Do this. I Added the Code but i am Getting Multiple Errors For my Play Button. I Haven't Tampered with the Orginal Code, and i've Written the Error at the locations of the Errors.</p>
  <p>The Errors im Getting Are</p>
  <blockquote>
  <p>Cannot resolve symbol 'PlayButton'</p>
  </blockquote>
  <p>And</p>
  <blockquote>
  <p>Cannot resolve method 'addView(PlayButton, android.widget.LinearLayout.LayoutParams)'</p>
  </blockquote>
  <p>Anyone got any Ideas to Why im getting these Errors?</p>
  <pre><code>import androidx.annotation.NonNull;
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.core.app.ActivityCompat;
  
  import android.Manifest;
  import android.content.Context;
  import android.content.pm.PackageManager;
  import android.media.MediaPlayer;
  import android.media.MediaRecorder;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.Button;
  import android.widget.LinearLayout;
  
  import java.io.IOException;
  
  public class MainActivity extends AppCompatActivity {
  
  
      private static final String LOG_TAG = &quot;AudioRecordTest&quot;;
      private static final int REQUEST_RECORD_AUDIO_PERMISSION = 200;
      private static String fileName = null;
  
      private RecordButton  recordButton = null;
      private MediaRecorder recorder = null;
  
      private PlayButton  playButton = null;     //ERROR HERE:  Cannot resolve symbol 'PlayButton'
      private MediaPlayer player = null;
  
      // Requesting permission to RECORD_AUDIO
      private boolean permissionToRecordAccepted = false;
      private String [] permissions = {Manifest.permission.RECORD_AUDIO};
  
      @Override
      public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
          super.onRequestPermissionsResult(requestCode, permissions, grantResults);
          switch (requestCode){
              case REQUEST_RECORD_AUDIO_PERMISSION:
                  permissionToRecordAccepted  = grantResults[0] == PackageManager.PERMISSION_GRANTED;
                  break;
          }
          if (!permissionToRecordAccepted ) finish();
  
      }
  
      private void onRecord(boolean start) {
          if (start) {
              startRecording();
          } else {
              stopRecording();
          }
      }
  
      private void onPlay(boolean start) {
          if (start) {
              startPlaying();
          } else {
              stopPlaying();
          }
      }
  
      private void startPlaying() {
          player = new MediaPlayer();
          try {
              player.setDataSource(fileName);
              player.prepare();
              player.start();
          } catch (IOException e) {
              Log.e(LOG_TAG, &quot;prepare() failed&quot;);
          }
      }
  
      private void stopPlaying() {
          player.release();
          player = null;
      }
  
      private void startRecording() {
          recorder = new MediaRecorder();
          recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
          recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
          recorder.setOutputFile(fileName);
          recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
  
          try {
              recorder.prepare();
          } catch (IOException e) {
              Log.e(LOG_TAG, &quot;prepare() failed&quot;);
          }
  
          recorder.start();
      }
  
      private void stopRecording() {
          recorder.stop();
          recorder.release();
          recorder = null;
      }
  
      class RecordButton extends androidx.appcompat.widget.AppCompatButton {
          boolean mStartRecording = true;
  
          View.OnClickListener clicker = new View.OnClickListener() {
              public void onClick(View v) {
                  onRecord(mStartRecording);
                  if (mStartRecording) {
                      setText(&quot;Stop recording&quot;);
                  } else {
                      setText(&quot;Start recording&quot;);
                  }
                  mStartRecording = !mStartRecording;
              }
          };
  
          public RecordButton(Context ctx) {
              super(ctx);
              setText(&quot;Start recording&quot;);
              setOnClickListener(clicker);
          }
      }
  
  
      @Override
      public void onCreate(Bundle icicle) {
          super.onCreate(icicle);
  
          // Record to the external cache directory for visibility
          fileName = getExternalCacheDir().getAbsolutePath();
          fileName += &quot;/audiorecordtest.3gp&quot;;
  
          ActivityCompat.requestPermissions(this, permissions, REQUEST_RECORD_AUDIO_PERMISSION);
  
          LinearLayout ll = new LinearLayout(this);
          recordButton = new RecordButton(this);
          ll.addView(recordButton,
                  new LinearLayout.LayoutParams(
                          ViewGroup.LayoutParams.WRAP_CONTENT,
                          ViewGroup.LayoutParams.WRAP_CONTENT,
                          0));
          playButton = new PlayButton(this);      //ERROR HERE: Cannot resolve symbol 'PlayButton'
          ll.addView(playButton,
                  new LinearLayout.LayoutParams(
                          ViewGroup.LayoutParams.WRAP_CONTENT,
                          ViewGroup.LayoutParams.WRAP_CONTENT,
                          0));     // ERROR HERE: Cannot resolve method 'addView(PlayButton, android.widget.LinearLayout.LayoutParams)'
  
          setContentView(ll);
      }
  
  
      @Override
  
      public void onStop() {
          super.onStop();
          if (recorder != null) {
              recorder.release();
              recorder = null;
          }
  
          if (player != null) {
              player.release();
              player = null;
          }
      }
  }
  
  
  </code></pre>