Android Studio: underscores in literals are not su

2019-09-16 15:48发布

问题:

I have a problem with the drawable class in R.java file. I had drawable hdpi, mdpi, xhdpi... folders in main/res, but drawable was missing so i created it by hand. Main.xml is able to find the image declared but this code in R.java gives an error:

    public static final class drawable {
    public static final int 10_device_access_accounts=0x7f020000;
    public static final int 10_device_access_add_alarm=0x7f020001;
    public static final int 10_device_access_alarms=0x7f020002;
    public static final int 10_device_access_battery=0x7f020003;
    public static final int 10_device_access_bightness_low=0x7f020004;
    public static final int 10_device_access_bluetooth=0x7f020005;
    public static final int 10_device_access_bluetooth_connected=0x7f020006;
    public static final int 10_device_access_bluetooth_searching=0x7f020007;
    public static final int 10_device_access_brightness_auto=0x7f020008;
    ...}

When compiled gives out an error: Gradle: error: underscores in literals are not supported in -source 1.6 (use -source 7 or higher to enable underscores in literals)

I'm using android studio version 1.0.0.1 and jdk 1.7.0.250 version, i have PATH variable pointing to %JAVA_HOME%\bin and CLASSPATH pointing to %JAVA_HOME%\lib

回答1:

removing the "10_" at the beginning of your files can fix the issue. For the reason why you can't have a resource with a numeric name, read this . If theses drawable ressources are icons, you can use the common naming conventions that you can read here, and begin your icons by "ic_" or "ic_menu" if this is Menu icons and Action Bar icons.