Error(1,1)illegalcharacter '\ufeff' when compiling on android studio

64,043

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

Android studio file encoding

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

enter image description hereAt bottom right of the project change file encoding UTF-8 to UTF-16.

  1. A new dialog will get open. Select convert it and run it.
  2. It will give you some errors then again change UTF-16 to UTF-8.
  3. Convert it and run the project. This time your project will run successfully.

Solution 5

i solved this problem with this method :

  1. ctrl + A in my activity and copy all codes
  2. delete YourClass.java
  3. create YourClass.java
  4. paste all code in new java class

This method work for me. tnx

Share:
64,043

Related videos on Youtube

Bruce
Author by

Bruce

Updated on July 12, 2022

Comments

  • Bruce
    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

    http://developer.android.com/sdk/installing/migrate.html

    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
      Alexey Ten about 10 years
      I'm quite sure that is BOM (byte order mark). Save your file as "UTF-8 without BOM"
    • Bruce
      Bruce about 10 years
      seems there is no option "without BOM"
    • Alexey Ten
      Alexey Ten about 10 years
      Find 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
      Alexey Ten about 10 years
      Looks like a bug of Android Studio stackoverflow.com/questions/17151830/…
    • Bruce
      Bruce about 10 years
      @alexeyten I fix it with Notepad++,appreciate for your advice
    • Marka A
      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
    Marka A over 8 years
    This solved it for me using Sublime Text on my end. Thanks.
  • anand krish
    anand krish about 8 years
    yeah.. 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
    Darshn almost 8 years
    welcome 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
    Etsitpab Nioliv over 7 years
    Solved 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
    Kyaw Min Thu L over 7 years
    I used XCode to remove illegal character from my file. Now it is fine. Thanks.
  • Mahdi Javaheri
    Mahdi Javaheri almost 7 years
    it helped me, Thanks
  • Solo
    Solo almost 7 years
    Helped me. Thanks!
  • Mohammed Shareef C
    Mohammed Shareef C over 6 years
    Comments and answers are different!
  • Keshav Gera
    Keshav Gera about 4 years
    If UTf-8 not show in android studio bottom bar then ctl+shift+n open LoopView Class then so Bottom Bar
  • Keshav Gera
    Keshav Gera about 4 years
    if ISO-8859-1' is bot show then please open LoopView file then show it in bottombar