3

I have huge number of sound bytes which I want to use in my project. Unfortunately all files are named numerically like "001.m3 , 002.mp3 ...."

When I added files in raw folder, Android R file gives error.

How can I solve this problem. Can any one provide me link where android has mentioned naming conventions for resource files.

Romio
  • 140
  • 1
  • 8

2 Answers2

2

The problem that you are facing is because of your file names, since your file name is 001.mp3 or 002.mp3. Android creates R.java file automatically, and in that file(R.java) it will create a variable by that file name which is variable name "001". Having a numeric variable name is wrong . It will not allow such thing and instead throw an error.

If your file is 001.mp3 then R.java will have error in this line which is

Syntax error on token "001", invalid VariableDeclaratorId

public static final int 001=0x7f050000;

I request you to change your file names. May be follow the recommendations Are there conventions on how to name resources?

Community
  • 1
  • 1
VendettaDroid
  • 3,131
  • 2
  • 28
  • 41
2

Every resources having entry in R.java file, If you see R.java file is nothing but like our normal class

public final class R {
    public static final class raw {
        public static final int 001=0x7f090005; // this will not accept as a variable name
    }

    public static final class drawable {
    }

    public static final class id {
        public static final int main=0x7f090001;
    }
}

You should follow the same Naming Convention like we do have for Variables i.e.

1) Must not start with number

2) Must not contain Special character except(_)

3) Must not used Reserved Keyword mentioned here

Solution: You have to rename you files, thats it.

Community
  • 1
  • 1
Mohammed Azharuddin Shaikh
  • 41,633
  • 14
  • 96
  • 115