views:

82

answers:

3

It's good to have consistency in file names.

MyActivity.java contains the public class MyActivity

I would like the xml file with its layout to be called res/layout/MyActivity.xml

But I get an error message saying "Invalid file name: must contain only [a-z0-9_.]"

So two questions:

  1. Why is the character set so limited (not even upper case? Come on!) - Ah - this restriction is probably in place so you will never be screwed by filesystems that don't make a distinction between upper and lower case, like Apple's HFS+ (although see Wikipedia for the gory story http://en.wikipedia.org/wiki/Comparison_of_file_systems#cite_note-note-35-77 )

  2. Which filenames are restricted - all of res? just res/layout? res/layout plus some other folders?

Can anyone confirm 1, and give details on 2?

Thanks,

Peter

+1  A: 

Not sure of the reason for #1. Never seen an explanation in any readings about Resources. For #2 from my experience anything that will be used as a id in java e.g., R.drawable.marker, R.string.default_message has to follow those rules of [a-z0-9_].

BrennaSoft
+5  A: 

Why is the character set so limited

Because the name has to be a valid Java identifier, so you can use constants like R.layout.foo to identify the layout at runtime.

Which filenames are restricted - all of res? just res/layout? res/layout plus some other folders?

Anything in res/

CommonsWare
But... I have upper case letters in my Java code...
Peter vdL
That part I can't explain, other than your OS filesystem theory.
CommonsWare
Thanks for a plausible explanation, but I wonder if there is more.
Peter vdL
Mark -- thank you so much -- I was just looking at your Busy Coder book today, and thinking "I have got to buy a copy of this" (and also groaning at the learning curve implied). Cheers, Peter
Peter vdL
+1  A: 

how dare you question Google's motives! :) (j/k)

Ben