Java 在android studio上编译时出现错误(1,1)非法字符'\ufeff'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23211589/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error(1,1)illegalcharacter '\ufeff' when compiling on android studio
提问by Bruce
I got an Eclipse project source code(I was told that on Android Studio, maybe they just confused), and I start to migrating the code to android studio refers to
我得到了一个 Eclipse 项目源代码(有人告诉我在 Android Studio 上,也许他们只是混淆了),然后我开始将代码迁移到 android studio 指的是
But it doesn't work. so I import the project from path directly and it transfers to the android-studio project automatically, but still, something wrong when I am compiling.
但它不起作用。所以我直接从路径导入项目并自动转移到android-studio项目,但是在我编译时仍然出现问题。
Error:(1, 1) error: illegalcharacter: '\ufeff'
错误:(1, 1) 错误:非法字符:'\ufeff'
the error position refers to
错误位置是指
package com.bla.blabla;
包 com.bla.blabla;
Please help me, thanks
请帮帮我,谢谢
回答by Diamond
That's a problem related to BOM (Byte Order Mark) character. Byte Order MarkBOM is a Unicode character used for defining a text file byte order and comes in the start of the file. Eclipse doesn't allow this character at the start of your file, so you must delete it. For this purpose, use a rich text editor, such as Notepad++, and save the file with encoding "UTF-8 without BOM." That should remove the problem.
这是与 BOM(字节顺序标记)字符相关的问题。字节顺序标记BOM 是用于定义文本文件字节顺序的 Unicode 字符,位于文件的开头。Eclipse 不允许在文件开头使用此字符,因此您必须将其删除。为此,请使用富文本编辑器,例如 Notepad++,并使用“UTF-8 without BOM”编码保存文件。那应该可以消除问题。
回答by Marcelo Amorim
On lower-right corner, you can set the file encoding. Select another option than UTF-8
在右下角,您可以设置文件编码。选择 UTF-8 以外的其他选项
If a popup appear, choose the option Convert
.
如果出现弹出窗口,请选择选项Convert
。
回答by Darshn
As Marcelo told, I changed file Encoding option to UTF-16. Ran it, But didn't work. Again changed to UTF-8 and Converted it. It ran successfully. If above solution doesn't work, try this.
正如马塞洛所说,我将文件编码选项更改为 UTF-16。运行它,但没有奏效。再次更改为 UTF-8 并转换它。它运行成功。如果上述解决方案不起作用,请尝试此操作。
回答by Sahil Verma
I was facing this error in intelliJ-2016.1.2.
我在 intelliJ-2016.1.2 中遇到了这个错误。
Thank you @Darsh for your help, I did same thing, first changed to UTF-16 (i.e convert into UTF-16) and compiled the code. it didn't work, then again changed back to the UTF-8, this time it worked fine.
谢谢@Darsh 的帮助,我做了同样的事情,首先改为 UTF-16(即转换为 UTF-16)并编译代码。它没有用,然后又改回 UTF-8,这次它工作得很好。
Thank you.
谢谢你。
回答by Kai Wang
Above are great solutions. However, if none of them works, try this one:
以上是很好的解决方案。但是,如果它们都不起作用,请尝试以下方法:
Open the file in Notepad++; Copy everything; Create a new file with the same name; Paste everything; Save it.
在 Notepad++ 中打开文件;复制一切;创建一个同名的新文件;粘贴一切;保存。
Now it is gone.
现在它不见了。
回答by mmmartinnn
I tried several of the other answers here with no joy.
我在这里尝试了其他几个答案,但并不高兴。
In the end I simply deleted the offending line and rewrote it directly into Android Studio
. The error disappeared.
最后,我干脆删除了违规行并将其直接改写为Android Studio
. 错误消失了。
Was this caused by me copying and pasting the line of code from youtube (or whatever random blog I was looking at at the time)?
这是由于我从 youtube(或我当时正在看的任何随机博客)复制和粘贴代码行造成的吗?
回答by Muhammad Laraib Khan
At bottom right of the project change file encoding UTF-8 to UTF-16.
在项目的右下角将文件编码 UTF-8 更改为 UTF-16。
- A new dialog will get open. Select convert it and run it.
- It will give you some errors then again change UTF-16 to UTF-8.
- Convert it and run the project. This time your project will run successfully.
- 将打开一个新对话框。选择转换并运行它。
- 它会给你一些错误,然后再次将 UTF-16 更改为 UTF-8。
- 转换它并运行项目。这一次您的项目将成功运行。
回答by Curio
Close android studio and reopen it. It works for me. Furthermore this could happen if you are copying a comment from youtube for example and pasting it into your project
关闭android studio并重新打开它。这个对我有用。此外,如果您从 youtube 复制评论并将其粘贴到您的项目中,则可能会发生这种情况
回答by Ahmad Aghazadeh
You can try to this method:
你可以试试这个方法:
- Rename the class like class1.java
- Create a new class some renamed class like class.java
- Select all contain renamed file and copy into the new class.
- 将类重命名为 class1.java
- 创建一个新类,一些重命名的类,如 class.java
- 选择所有包含重命名的文件并复制到新类中。
This method work for me.
这种方法对我有用。
回答by Bonnie Milian
I try using sublime, open the file then "Save with Encoding" there choose UTF-8 (without BOM), and it works :)
我尝试使用 sublime,打开文件然后“使用编码保存”,然后选择 UTF-8(没有 BOM),它可以工作:)