Error(1,1)illegalcharacter '\ufeff' when compiling on android studio
Solution 1
That's a problem related to BOM (Byte Order Mark) character. Byte Order Mark BOM 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.
Solution 2
On lower-right corner, you can set the file encoding. Select another option than UTF-8
If a popup appear, choose the option Convert
.
Solution 3
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.
Solution 4
At bottom right of the project change file encoding UTF-8 to 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.
Solution 5
i solved this problem with this method :
- ctrl + A in my activity and copy all codes
- delete YourClass.java
- create YourClass.java
- paste all code in new java class
This method work for me. tnx
Related videos on Youtube
Bruce
Updated on July 12, 2022Comments
-
Bruce almost 2 years
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
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.
Error:(1, 1) error: illegalcharacter: '\ufeff'
the error position refers to
package com.bla.blabla;
Please help me, thanks
-
Alexey Ten about 10 yearsI'm quite sure that is BOM (byte order mark). Save your file as "UTF-8 without BOM"
-
Bruce about 10 yearsseems there is no option "without BOM"
-
Alexey Ten about 10 yearsFind an editor that could save file without BOM. If your file doesn't contains characters beyond ASCII you could save it with notepad as ANSI
-
Alexey Ten about 10 yearsLooks like a bug of Android Studio stackoverflow.com/questions/17151830/…
-
Bruce about 10 years@alexeyten I fix it with Notepad++,appreciate for your advice
-
Marka A over 8 years@Bruce did mine (opening and Saving with encoding then saving with UTF "without" BOM)... I used Sublime to do it... Thanks....
-
-
Marka A over 8 yearsThis solved it for me using Sublime Text on my end. Thanks.
-
anand krish about 8 yearsyeah.. It worked. I have copy pasted the same content from a website to a Notepad++, it shows the "LS" with black background. After deleted that I have copy the same content from notepad++ to java, it works fine.
-
Darshn almost 8 yearswelcome mate and Welcome to StackOverflow. Please write a comment below solution which i have provided. Do not write as the answer :) Happy coding :)
-
Etsitpab Nioliv over 7 yearsSolved the problem for me, but please note that converting and copy pasting afterwards did not work. Open the file in your project folder to make this work.
-
Kyaw Min Thu L over 7 yearsI used XCode to remove illegal character from my file. Now it is fine. Thanks.
-
Mahdi Javaheri almost 7 yearsit helped me, Thanks
-
Solo almost 7 yearsHelped me. Thanks!
-
Mohammed Shareef C over 6 yearsComments and answers are different!
-
Keshav Gera about 4 yearsIf UTf-8 not show in android studio bottom bar then ctl+shift+n open LoopView Class then so Bottom Bar
-
Keshav Gera about 4 yearsif ISO-8859-1' is bot show then please open LoopView file then show it in bottombar