tags:

views:

55

answers:

4

Actually I have 52 images which r basically cards. images names are from 1 to 52.

when I put all the 52 images in my drawable folder then it is showing an error in R.java file which is:

Syntax error on token "image name(any between between 1 to 52)", invalid VariableDeclaratorId

what is the problem?

+1  A: 

Resource names have to be proper Java identifiers. Call them card1 through card52 instead of just their numbers (if I understand you correctly).

EDITED TO ADD: To map an integer to the correct image, your code should manage the mapping itself. One (not terribly elegant) way is to explicitly create a Bitmap[] cardImages = new Bitmap[52]; array and assigning each resource into the array, as in e.g.

Resources r = context.getResources();
cardImages[0] = loadBitmap(r.getDrawable(R.drawable.card1));
// ...
cardImages[12] = loadBitmap(r.getDrawable(R.drawable.card13));
// ...    
cardImages[51] = loadBitmap(r.getDrawable(R.drawable.card52));
Pontus Gagge
A: 

Hi Pontus Gagge..

thanks for replying.

i think u didnt get my problem.

i have given name to my cards from 1 to 52 because i need to randomly select one card from it.

vivek_Android
Vivek please use the comment functionality to reply to answers instead of using the answer section.
Janusz
+1  A: 

The problem is that Android doesn't allow to use spaces in a file identifier

Roflcoptr
then what is the sollution?
vivek_Android
the solution is to not use spaces
Roflcoptr
There are no spaces in his variable names.
Janusz
he edited the question
Roflcoptr
A: 

Pontus Gagge is right. Android will take the name of the everything in the drawable folder and will try to generate an R file that contains an int for every image that you are using in your app. The ints are named after the file names of your drawables. You can then later use this ints as ids to load the images from your app.

The problem is that Java does not allow a vairable name to start with a number. Your images start with a number therefore your variables in the R file will start with a number. You have to choose another name for your images.

Janusz