3

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
  • 11,279
  • 21
  • 61
  • 85

3 Answers3

8

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.

William Morrison
  • 10,953
  • 2
  • 31
  • 48
  • Sure I had this raw folder withe the mp3 file inside. In fact, I restarted my ide (`Android Studio`) and it worked ;) – epsilones Aug 08 '13 at 19:29
  • 1
    Great! Yeah these auto-generation tools sometimes have synchronization problems with IDE's. Please accept an answer to close the question @Newben – William Morrison Aug 08 '13 at 19:30
4

"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)

Philipp Jahoda
  • 50,880
  • 24
  • 180
  • 187
0
  • You need to right-click on res->new->Android resource directory.

  • Select raw in resource type and it automatically selects raw as the directory name.

  • Drag and drop your .mp3 music file inside the res folder. Make sure that it starts with a small letter.