43

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

Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98
Bruce
  • 1,645
  • 3
  • 15
  • 14

15 Answers15

39

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.

Community
  • 1
  • 1
Diamond
  • 598
  • 5
  • 15
  • This solved it for me using Sublime Text on my end. Thanks. – Marka A Jan 20 '16 at 03:03
  • 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. – anand krish Mar 15 '16 at 12:05
  • 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. – Etsitpab Nioliv Feb 03 '17 at 09:24
  • 1
    I used XCode to remove illegal character from my file. Now it is fine. Thanks. – Kyaw Min Thu L Feb 14 '17 at 10:29
34

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.

Marcelo Amorim
  • 1,662
  • 23
  • 23
19

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.

Darshn
  • 1,512
  • 1
  • 23
  • 31
13

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.
Muhammad Laraib Khan
  • 6,508
  • 2
  • 16
  • 13
6

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 worked for me. tnx

Ali Yazdanifar
  • 372
  • 4
  • 12
3

I was facing this error in 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.

Thank you.

Sahil Verma
  • 131
  • 3
  • 12
2

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.

Now it is gone.

Kai Wang
  • 3,303
  • 1
  • 31
  • 27
2

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.

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)?

mmmartinnn
  • 387
  • 4
  • 16
2

You can try to this method:

  1. Rename the class like class1.java
  2. Create a new class some renamed class like class.java
  3. Select all contain renamed file and copy into the new class.

This method work for me.

Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98
1

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

Curio
  • 1,331
  • 2
  • 14
  • 34
1

I try using sublime, open the file then "Save with Encoding" there choose UTF-8 (without BOM), and it works :)

1

Simply go in notepad plus plus and open your file and in encoding option at the top bar just select utf8

1

OPEN LOOPView.java File First

Convert Your UTF8 To ISO 8859-1 TO Solve your problem In andorid Studio

If UTf-8 not show in android studio bottom bar then ctl+shift+n open LoopView Class then so Bottom Bar

enter image description here

enter image description here

Note ISO-8859-1 Use this

If your error not resolved then Invalidate cache and Restart again and

gradlew clean npm start -- --reset-cache react-native run-android react-native run-ios

Solve Your issue permenantly

One Other Thing if issue still persist then com.wheel file copy into notepad++ and again copy and paste in your project

 android {  
   compileOptions.encoding = 'ISO-8859-1'
 }

In React-native change in index.js / android/index.js

import PropTypes from 'prop-types';

Keshav Gera
  • 10,807
  • 1
  • 75
  • 53
0

Just delete the first line of the xml-file and retype it by hand (copy paste would reinsert the hidden BOM).

0

The ideas in here certainly helped me but the outcome was a little different.

I did convert my file encoding from UTF-8 to UTF-16. I was then presented with a different error. When i converted it back to UTF-8, I noted that there was a string of unrecognizable characters before my code line. I removed them and recompiled and it worked well.

My conclusion is somehow an unrecognizable character snuck into my code. Could be programmer error, or a blind copy/paste from the web that placed a nasty hidden character. Carrying the process above as outlined by our peers here somehow allowed me to see it.

If you'll follow this idea above, please make sure to clean/rebuild between each conversion.

Sol Sadek
  • 11
  • 3