Strange error in R.java, even after cleaning the project: “Underscores can only be used with source level 1.7 or greater”

一个人想着一个人 提交于 2019-12-04 23:40:49

This is a combination of two things:

  1. Java identifiers cannot start with a digit. The first character should be a letter.

  2. In Java 7, they introduced alternative syntaxes for integer literals; e.g. 1_000 is the same as 1000.

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".

I just now tried renaming an existing drawable in a compiling-fine Android project of mine and Eclipse threw this dialog up:

(If you can't see the image very well, the dialog box is saying The resource name must begin with a character.

The way that I produced this dialog was renaming a drawable file. The drawable's original name was button_blue_normal.9.png, renamed it to 5_button_blue_normal.9.png and pressed enter. Dialog popped up immediately after pressing enter.

I never knew this but apparently you'll need a letter-character, not a digit, at the very beginning of a drawable's file name.

I know I'm late to the party but I just ran into this myself when I started working with the ActionBar component.

ScootrNova's answer led me to the solution. The problem was the Android-recommended icon pack that I downloaded for use in the tutorials. All the filenames began with integers (1_xxx.png, etc). I removed the ones I wasn't using, renamed the others to something that began with a letter (I used "icon_xxx.png" as an example), and it compiled without error.

I had the same problem and I solved it after putting digit after text not at begining. I had line 2_Activity and I changed it to Activity2. It was my solution. Hope that it will help someone.

I had the same problem. Resolution: Look at the res files, drawlables or inside xml and rename files or strings that start with (number underscore string) 1_string to string_1.

Hope this helps to resolve the problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!