about 'Syntax error on token "Invalid Character", delete this token'

来源:互联网 发布:西师大知行学院咋样 编辑:程序博客网 时间:2024/05/17 12:50

problem

someone may encounter build problem commenting as the title shows, while import an existed project from other place.

mostly you are setup a java project, from Windows OS to Mac, or between pure text editor and IDEs like Eclipse or Android Studio.

it is sure that the problem not related to your coding skills as you will not find any programming errors or mis-type and it works well from the original project environment.

when i first met the problem, i search on the Internet for long time, some may simply telling there are invalid tailing character that are not compatible between different environments but not visible, some may just sharing the way they solving the similar case they met.

while firstly got the explanations, i have the thought of "so it is". but when i follow and try most methods they used to solve their problem, failure comes one by one:

clear the tailing words and retype them manually;

checking if any unsupported words in the error lines;

transfer the sourcecode file(s) among Dos/Mac and Unix code style;

change to UTF16 and back to your original encoding type.

have a try

i realized that it may be file encoding related, and above solutions should really solved the problem under some situations while not feat mine. the explanation provided may too rough to tell the details so that we can follow by the real situations.

by save the original file into different types(using gEdit from Ubuntu), the file size also differs. changing the encoding style directly by NotePad++(under Windows), english words not changed by view(from UI visible aspect) but file size changed, so we could not tell what happens for the bit content background. while if there are special words which may be explained into different meanings, Chinese word for example, the visible words changed from UI under different encoding style. so i think the differences may not simply an tailing words difference(CRLF terminate line or not).

and i also find another post seems more explain the problem more details(list at the bottom): even coded UTF-8 details are not consistent, a BOM, a no. this words referenced directly from the post.

so i try to identify the building passed files and the error one by "file" cmd:

#failure one$file Demo/src/com/tense/demo/DemoService.javaDemo/src/com/tense/demo/DemoService.java: UTF-8 Unicode (with BOM) text, with CRLF line terminators#success one$file fService/src/com/hservice/RadioService.javafService/src/com/hservice/RadioService.java: ASCII text$file Demo/src/com/tense/demo/LogUtil.javaDemo/src/com/tense/demo/LogUtil.java: ASCII text, with CRLF line terminators
to make the least changes and verify if just related to BOM(byte order mark), simply clear the BOM(by NotePad++), and then got:

$file Demo/src/com/tense/demo/DemoService.javaDemo/src/com/tense/demo/DemoService.java: UTF-8 Unicode text, with CRLF line terminators

then the code build pass!!!

so you will find that if the tailing words is "CRLF terminated" or not should have no impact.

while as there may be other words invisible but have different meanings under different encoding style, if there is few lines encounter this Syntax error, you can check firstly for retyping tailing words and any unreadable words in the line. if the error occurs since the first line of the file and no any detail comments from build info, try to convert file encoding style to the same with your local passed files.

below is the content of the reference post:

==========================================

Eclipse Syntax error on token in " Invalid Character" delete this, token error, Look at the code is not the problem, Check the Internet for a long time found that the problem does not seem too much, To summarize the reasons of the problems and Solutions.

See the first thought is not Chinese punctuation, or full width half angle of the problem, through the examination, this problem does not exist.


Then see a post that have the same error is introduced into the eclipse project by Android Studio, eclipse and idea for the same reason is coded UTF-8 details are not consistent, a BOM, a no.

What is the full name of BOM is BOM?: Byte order mark. UTF-8 in a byte code unit, not byte ordering problems. UTF-16 two byte encoding unit, in the interpretation of the text of a UTF-16 before, we must first clarify sequence bytes each coding unit. For example, Unicode code received a "Kui" is 594E, "Unicode coding B" is 4E59. If we received UTF-16 bytes stream "594E", it is "Kui" or "B"? Marker byte order recommended in the Unicode specification is BOM. BOM is not "Bill Of Material" BOM, but Byte Order Mark. In the UCS code is called a " ZERO WIDTH NO-BREAK SPACE" character, its code is FEFF. While the FFFE in UCS is not the existence of characters, so should not appear in the actual transmission. The UCS specification suggest transmission byte stream, the first transmission character"ZERO WIDTH NO-BREAK SPACE". So if the receiver receives the FEFF, the byte stream is Big-Endian; if FFFE, indicates the byte stream is Little-Endian. Therefore the character " ZERO WIDTH; NO-BREAK SPACE" also known as BOM.

UTF-8 does not require the BOM to show the byte order, but can show the coding with BOM. The character " ZERO WIDTH NO-BREAK; SPACE" UTF-8 code is EF BB BF. So if the recipient received by EF BB BF at the beginning of the byte stream, know that it is the UTF-8 code.

16 hexadecimal form through the UE to view the file, including EF BB BF found that at the beginning of series, eclipse will not be identified as ordinary character processing, so the error.

(solution skipped as not mine)

==========================================

reference:

http://www.programering.com/a/MTM1YTNwATU.html

https://stackoverflow.com/questions/7129371/syntax-error-on-token-invalid-character-delete-this-token

https://stackoverflow.com/questions/20718116/android-programming-syntax-error-on-token-invalid-character-delete-this-toke

https://github.com/Damao/Intellij-IDEA-F2E/blob/master/FAQ/%E9%97%AE%E9%A2%98%E9%9B%86%E5%90%88/Eclipse%E9%A1%B9%E7%9B%AE/IDEA%E7%BC%96%E8%AF%91%E5%87%BA%E9%94%99.md

阅读全文
0 0
原创粉丝点击