Skip to content
Advertisement

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();
            }
        });

        }

}

Advertisement

Answer

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

Advertisement