I\'m building an MP3 player into my app and I\'m getting an error stating \"raw cannot be resolved or is not a field\" on the line: mMediaPlayer = MediaPlayer.create(this, R
I'm not sure exactly what R.raw.test_cbr is (I did not write this code) can someone explain what R.raw.test_cbr is as well as how this can be resolved?
R.raw
refers to the "raw" resources placed in res/raw
. "Raw" means that the resource file is included in the application package as-is, without any compile-time modifications.
(In theory at least. I've had problems where the toolchain modified my raw resources but that's beyond the scope of this question.)
You get this compile time error because you don't have the res/raw
folder and the R.raw
nested class is not generated in R.java
.
R.raw.test_cbr
refers to a file test_cbr.ext
in the res/raw
folder, where ext
is just some file extension.
Since you're feeding MediaPlayer
, you should place some audio media file test_cbr
e.g. text_cbr.mp3
in res/raw
and rebuild your application.
The raw folder goes inside res folder of your Android Project. Onces inside /res, you cand find it through R.raw
When I faced the issue, there was another issue. The name of the resource should contain only lowercase letters. If not, any reference to R causes an issue. Also extension is compulsory