Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in strings.xml: invalid symbol 'continue'

Tags:

android

In my strings.xml file I have

<string name="continue">Continue</string>

I can't build my project because of the error: "Invalid symbol: 'continue'". Why I can't use such a name?

like image 562
Eugene Avatar asked Oct 21 '11 13:10

Eugene


2 Answers

It's because continue is a reserved symbol in Java, so you cannot use it as a name for any object in your XML files or Java code.

The reason this is a problem is that the XML defined in your project is translated into Java code that the Dalvik VM can understand. So, your code above translates into the following in R.java:

public final class R {
    public static final class string {
        public static final int continue=0x7f040000;
    }
}

The problem is more obvious when examining the (would-be) generated code.

See list of reserved Java symbols for others to avoid.

like image 113
Justin ᚅᚔᚈᚄᚒᚔ Avatar answered Oct 22 '22 15:10

Justin ᚅᚔᚈᚄᚒᚔ


"continue" is a Java keyword and the R.java would not compile.

public static final int continue=0x7f040001;

the above code would cause an "Syntax error on token "continue", invalid VariableDeclaratorId" error.

like image 21
lukuluku Avatar answered Oct 22 '22 17:10

lukuluku