Android Raw folders - creation and reference

AndroidAndroid Resources

Android Problem Overview


I'm trying to create a raw folder for my android app which will hold different media files for use later. But I can't seem to be able to reference the created raw folder in my .java classes.

For example: R.? -> This returns a list of all possible resources I can use like the basic drawable, layout and values folder. However it won't display the raw folder.

Is it correct to say that raw is created as a general folder and nothing else? Or does it have to be declared in the AndroidManifest.xml file in order to be recognised as a resource?

Android Solutions


Solution 1 - Android

The raw folder must be inside the res folder, otherwise it won't work.

Solution 2 - Android

Right click on package click on new on popup then click on android resource directory a new window will be appear change the resource type to raw copy and past song to raw folder remember don't drag and drop song file to raw folder and song spell should be in lower case This method is for Android Studio Link enter image description here

Solution 3 - Android

General folder will get error if you create and put some file into it. Put some media file into raw folder then you can able to refer the raw folder into your .java files.

Hope it will clear all your doubts.

Solution 4 - Android

Just create 'raw' inside 'res' folder and place media file inside that raw folder. Then try to access that media file through your program like R.raw.mediaFile

Solution 5 - Android

When I created raw folder inside res for the first time, I was not able to access it using R.raw but still I use R.raw.music in my code [showing me error that can not reference to this folder] and when deploy the app that error gone away, my app run without any problem. After that, I was able to access raw folder using R.raw.

Solution 6 - Android

In Android Arctic Fox

Click right on App -> New -> Folder -> Raw Resources Folder

enter image description here

Solution 7 - Android

Another answer on Stack Overflow helped with this. You can just go to Build > Clean Project and that will automatically resolve your issue.

Solution 8 - Android

You also need to follow the naming convention while putting any media file in raw folder as well. In my case my file name was not correct and it was also prompting me an error that unable to find R file. But as @Kesha said it build successfully while it was prompting me an error as well

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKatana24View Question on Stackoverflow
Solution 1 - AndroidLeandroidView Answer on Stackoverflow
Solution 2 - AndroidMisbah FarooqiView Answer on Stackoverflow
Solution 3 - AndroidVivekView Answer on Stackoverflow
Solution 4 - AndroidstackUnderflowView Answer on Stackoverflow
Solution 5 - AndroidKeshaView Answer on Stackoverflow
Solution 6 - AndroidAmrDeveloperView Answer on Stackoverflow
Solution 7 - AndroidTechChefView Answer on Stackoverflow
Solution 8 - AndroidTabish HafeezView Answer on Stackoverflow