-2

I added an ID like this android:id="id/user name" with a space and now I have a compiler error in my R.java file. This is the report :

/home/eric/AndroidStudioProjects/QrClub/app/build/generated/source/r/debug/com/example/eric/qrclub/R.java
Error:(22, 40) error: ';' expected
Error:(22, 50) error: <identifier> expected
Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.

I think I have to delete user name from R.java but I'm not able to do...

Aleks G
  • 52,841
  • 25
  • 149
  • 233

2 Answers2

5

Android IDs can not have spaces in them. You should only ever use english alphabet characters and the "_" character. Also, first time when you are declaring an id you should use +id and you need an @ character before id;

android:id="@+id/user_name"
Squeazer
  • 1,215
  • 1
  • 11
  • 31
  • ok thanks but now i have this string in R.java "public static final int User name=0x7f080005;" and this give me error i want to know how to delete it... Thanks – Eric Tondelli Aug 22 '14 at 14:41
  • For anyone else looking for the same answer, if working in eclipse just clean your project and it will work. Also, you should NEVER manually change the R.java file – Squeazer Aug 23 '14 at 16:45
0

There is a nice discussion on naming conventions for Android IDs at:

Android id naming convention: lower case with underscore vs. camel case

I confess I hadn't heard the term "CamelCase" before reading this discussion. Well you learn something new every day.

Bottom line is that while spaces are not allowed, both upper and lower case characters are evidently allowed. Though I had the impression that one of my Eclipse based Android test programs had issues with a leading upper case character - so I have been defensively using ""@+id/a_b_c" type naming since then.

Community
  • 1
  • 1
Jim Andreas
  • 1,340
  • 1
  • 16
  • 29