I found in the last couple of Days a lot of simular Questions but neither gave me a working answer so pls excuse me for asking again, but maybe someone can 开发者_C百科help me...
Problem:
IDE: Eclipse 3.6.2; Android SDKIn order to load an small mp3 to the res/raw i created the folder raw in res... and added the file in the raw folder with New > File... so far so good...
BUT:
MediaPlayer mp = MediaPlayer.create(context, R.raw.sound_file_1);
mp.start();
R.raw or any other way to get raw wont work.... and i can't get to the sound_file
if i look in class R.java it don't contains raw... I really don't know what else i can do... Maybe someone can help me please... Thanks in advanceYou need to rebuild/recreate R.java - that file is generated on demand.
In Eclipse this may need a "clean & build" action. You may also refresh the project in the project view, it will repopulate all the assets and when you build, it will repopulate R.raw for you
In IntelliJ IDEA, you have a context menu option "Force generate R.java" when you stand on such a resource file.
NOTE The R file won't be re-generated if you have a compilation error in one of your Java/XML files
Thing you should be careful about :
1) that your file name doesn't contain any illigal caracters. if it does then it will fail to create the R file correctly and so you can't use R (the error message appears in the the regular eclipse console)
2) check that you have "loaded" your file to the project do ctrl (or cmd on mac)+shif+o on the root of your project in elcipse browser (reloads all resources) then F5 to refresh the files structures and the a clean project to force a nice clean build
3) you could check if you have the RIght R files imported to your project, there is a default R file something like android.R instead of projectPackages.R
hope this helps
Jason
If the file has an all-caps filename, rename the file to all lower case. (An error message might appear: "Invalid file name: must contain only [a-z0-9_.]") I wonder if it is related to the case preserving but case insensitive file system on a mac? (I'm developing on a Mac.)
Be Careful, the same thing happened to me. Check your imports, I had a mistake and wrote
import android.R;
Instead, I changed it for
projectroot.mypackage.R;
I had the same problem and I solved it.
The fact was that the file names were in Capital Ex
, Song1.mp3
... I only renamed it song1.mp3
and it works..
I renamed the music-file to only lower case letters and nothing else. Than it works (after long time researching).
Windows Explorer checks the audio file, not Eclipse.
精彩评论