I recently started developing applications in android and a lot of tutorials have said that we shouldn't use uppercase in naming the resources. Why is that? Also it is not allowed to give extensions such as .png and .xml. If i have two files button.png and button.xml how does the app differentiate between the two files?
-
Just naming convention followed i guess. – Raghunandan Mar 10 '13 at 09:57
-
app doesnt differentiate it you have to put them at right place for app they both are resource – DjHacktorReborn Mar 10 '13 at 09:57
-
But in one of the tutorials they put an xml file and a png file with the same file name in the folder @drawable/ – Akas Antony Mar 10 '13 at 10:00
-
name them button_image.png, and button_layout.xml – IAmGroot Mar 10 '13 at 10:01
2 Answers
not to allow uppercase letter in resources is just to follow some convention strictly
you can not use two different types of resources of a same name in the same resource folder. for example say you have two resource files in drawable-hpdi. they are a.png and a.xml. Here while compiling the compiler will show error. But if you place a.png in drawable-hdpi and a.xml in drawable-mdpi, then it will not show any error as these two resources will be used in two totally different device types.
Another interesting thing I found that if you use a.png and a.xml in same folder then the error will show that a.xml is duplicate. But if you use a.jpg and a.png in same folder then it will show that the a.png is duplicate. For that we can guess that there is no file type priority. The compiler follow a top down search. as a.png is placed over a.xml so the compliler will first find a.png then when they find xml file of same name they will show error. and for the same reason while using a.jpg and a.png, a.png will show error.
N.B. This answer is totally based on my observation. I didnt find any written documentation on this. So if anybody proves my wrong with proof then that will be highly appreciated

- 54,068
- 14
- 92
- 112
As the filename part of the resource file will be used to create a resource ID in the
generated Java file
gen/<your-package-path>/R.java
you cannot have the same resource file name with different extensions in the same directory.
See the use of the recource file name, in the resource reference for a Bitmap File
As the resource IDs are Java variables, it is a good practice to follow the Java proposed conventions for variables (see Wikipedia Naming conventions for Java) to start their names with lowcase letters.

- 351
- 3
- 7
-
Surely it should only enforce this by disallowing two resource files of different type with the same main name in the same directory? e.g myFile.png clashing with myFile.xml ? Java creates case sensitive stubs anyway so even if we didnt need to worry about case insensitive file systems there would not be an issue. Using different naming conventions for filenames over traditional Java camelCase style is slightly frustrating. – RichieHH Mar 14 '14 at 10:24