Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio: Cannot resolve symbol 'raw'

I've a resource directory called "raw" in the "res" folder, but still can't access it through my code. The problem occurs when trying to declare the MediaPlayer variable.

public class MainActivity extends AppCompatActivity {

    private MediaPlayer pSong;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        pSong = MediaPlayer.create(this,R.raw.rando);


        Button playButton = (Button) findViewById(R.id.play);

        playButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(MainActivity.this,"Play", Toast.LENGTH_SHORT).show();
            }
        });

        }

}
like image 587
HaakonFlaar Avatar asked Jun 18 '18 13:06

HaakonFlaar


3 Answers

Android Studio 3.6+:

Click on Build -> Rebuild Project and then click File -> Sync Project with Gradle Files

Android Studio 3.5 and earlier:

Click on Build -> Rebuild Project and then click Tools -> Android -> Sync Project with Gradle Files

like image 138
Akash Elhance Avatar answered Oct 10 '22 07:10

Akash Elhance


Rebuilding and Syncing did not work for me. Had to restart Android Studio.

like image 35
Matt Avatar answered Oct 10 '22 06:10

Matt


Android Studio 4+: Go to File -> Invalidate Caches / Restart this will let android studio to index the raw files.

like image 42
Methnani Bilel Avatar answered Oct 10 '22 05:10

Methnani Bilel