Categories
Android Eclipse Java SDK

Eclipse – “Syntax error on token “…”, invalid VariableDeclaratorId”

When you import an image into your res folder show following error message of type Java Problem:

Syntax error on token “{filename}”, invalid VariableDeclaratorId

because file name is invalid: must contain only [a-z0-9_.]
ie, file name must start with a lowercase letter, then it may contain lowercase/uppercase letters or numbers or underscores or dots.

Select file name on the Package Explorer then
click the right mouse button -> Refactor -> Rename
or

press Alt+Shift+R
and insert valid file name.

Did my solution solve your problem?

4 replies on “Eclipse – “Syntax error on token “…”, invalid VariableDeclaratorId””

Eclipse – "Syntax error on token "…", invalid VariableDeclaratorId" | PDA8says:

[…] Go to Source […]

In my xml layout file i had some incorrect tags, for example:
android:id=”@+id/4″
i removed it and it removed the r.java issues 🙂

Hi all,
this message gave me direction to resolve my problem. I got problem with R.java because one of my
android:id=”@+id/4abcdef began with a non-alphabetic caracter.

My project had a red flag visible in the Package Explorer, and when I went through the workspace to find out which line of code was concern, it didn’t give me anything. I only knew that R.java was in trouble. As R.java is a genereted file, I didn’t know which file was gulty.

I do find a hint by using the “Android Tools R Lint “.
You can access it by right clicking your projet and then choose Android Tools/Run R Lint Check for common errors.
At that time You will get some more information by having a look at Window/Show View/Problem.
Here You will have all information relative to what RLint find during is check. That gave me the number of the line in the R.java file that was in trouble. I just had to find which *.xml file in my layout folder mentionned the “android:id=”@+id/4”, and then put an alphabetic caracter immediately after the /.

FYI after using YourProject/Android Tools/ R Lint Check for common errors, ==> You need to access Clear Lint Markers, to autmatiquely correct most of the errors and warnings reported by R Lint. So right click YourProject/ and then Android Tools/Clear Lint Markers.

Enjoy.

Thanks to apologize my broken english, cause I’m a frenchy 😉
Olivier

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.