mediaplayer failing on R.raw - Android
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)
epsilones
Updated on June 24, 2022Comments
-
epsilones almost 2 years
Importing
import android.media.MediaPlayer
, I am toldraw cannot be resolved
inprivate void playSound(){ MediaPlayer mp = MediaPlayer.create(this, R.raw.Jam); ...
I am really new to
Android
, what israw
for ? and how can I fix this problem ?-
Raghunandan over 10 yearsstackoverflow.com/questions/5777413/…. /res/raw/Jam.mp3
-
JafarKhQ over 10 yearsIf you have raw folder the file name cant be in capital letter, rename it to jam
-
-
epsilones over 10 yearsSure I had this raw folder withe the mp3 file inside. In fact, I restarted my ide (
Android Studio
) and it worked ;) -
epsilones over 10 yearsSure I had this folder and the file inside, but I had to restart my ide and it worked ;)
-
William Morrison over 10 yearsGreat! Yeah these auto-generation tools sometimes have synchronization problems with IDE's. Please accept an answer to close the question @Newben