Issue
So everything was going quite nicely, until just a while ago when R.java decided to have this error after adding an icon (5_content_new.png
, to be exact).
I've tried cleaning the project and restarting eclipse, to no avail.
The problem code:
public static final class drawable {
public static final int 5_content_new=0x7f020000;
public static final int ic_launcher=0x7f020001;
...
}
The red line appears right under 5_
, and the error says:
Underscores can only be used with source level 1.7 or greater
Has anyone encountered a problem like this before?
Solution
This is a combination of two things:
Java identifiers cannot start with a digit. The first character should be a letter.
In Java 7, they introduced alternative syntaxes for integer literals; e.g.
1_000
is the same as1000
.
So what is happening is that the compiler is parsing 5_content_new
as 5_ content_new
... which is reasonable if the source level was Java 7, and then telling you that you are not using Java 7. If you HAD been using Java 7, that compilation error would have been replaced by an error that said that an integer literal (5_
) was not legal at that point.
In short, the code contains something so "off the wall" that the compiler writer didn't anticipate it in the compiler diagnostic code.
The other point is that using ANY underscores in a variable, method, class or package name in Java is a style violation. Underscores should only be used in all-caps constant names like "MAX_VALUE".
Answered By - Stephen C
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.