mediaplayer failing on R.raw - Android

13,668

Solution 1

A raw folder holds files of any type. You need a raw folder under your resources folder (res). In your example, jam is expected as a resource in the raw folder, and will likely be a type of music file as you're using MediaPlayer to try and read it.

You've this error raw cannot be resolved because raw folder doesn't exist, and so the variable raw in class R is not being auto-generated.

Fix the problem by creating the raw folder.

If you already have created res/raw try cleaning the project. Sometimes Eclipse gets confused. If that doesn't work, make a small change to a source file, and save it so the auto-build process kicks off. Sometimes cleaning manually hasn't fixed the problem for me, its a known bug for Eclipse.

Solution 2

"raw" is a (or should be) a folder in your Android Project, containing the file "Jam" in your case. ("Jam" will most likely be a .wav or .mp3 file)

Since "raw" cannot be resolved you probably do not have a folder called "raw" in your project. In order to get rid of the error create a folder called "raw" in your Android Project folder.

I am not 100% sure about this but I am also quite sure that files inside the "raw" folder cannot contain CAPITAL letters. (only a-z0-9)

Share:
13,668
epsilones
Author by

epsilones

Updated on June 24, 2022

Comments

  • epsilones
    epsilones almost 2 years

    Importing import android.media.MediaPlayer, I am told raw cannot be resolved in

     private void playSound(){
            MediaPlayer mp = MediaPlayer.create(this, R.raw.Jam);
    ...
    

    I am really new to Android, what is raw for ? and how can I fix this problem ?

  • epsilones
    epsilones over 10 years
    Sure I had this raw folder withe the mp3 file inside. In fact, I restarted my ide (Android Studio) and it worked ;)
  • epsilones
    epsilones over 10 years
    Sure I had this folder and the file inside, but I had to restart my ide and it worked ;)
  • William Morrison
    William Morrison over 10 years
    Great! Yeah these auto-generation tools sometimes have synchronization problems with IDE's. Please accept an answer to close the question @Newben