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

16

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

Gerhard answered 22/4, 2014 at 6:3 Comment(6)
I'm quite sure that is BOM (byte order mark). Save your file as "UTF-8 without BOM"Ova
seems there is no option "without BOM"Gerhard
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 ANSIOva
Looks like a bug of Android Studio #17152330Ova
@alexeyten I fix it with Notepad++,appreciate for your adviceGerhard
@Gerhard did mine (opening and Saving with encoding then saving with UTF "without" BOM)... I used Sublime to do it... Thanks....Sunup
P
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.

Philomel answered 22/2, 2015 at 22:31 Comment(4)
This solved it for me using Sublime Text on my end. Thanks.Sunup
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.Mesenchyme
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.Photoelectrotype
I used XCode to remove illegal character from my file. Now it is fine. Thanks.Rowdyism
H
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.

Halimeda answered 12/5, 2015 at 19:28 Comment(0)
A
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.

Armlet answered 11/11, 2015 at 5:50 Comment(0)
F
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.
Fairminded answered 15/2, 2017 at 11:2 Comment(2)
it helped me, ThanksDennis
Helped me. Thanks!Deloresdeloria
D
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

Daliadalila answered 11/9, 2018 at 8:2 Comment(0)
K
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.

Klansman answered 7/7, 2016 at 8:4 Comment(2)
welcome mate and Welcome to StackOverflow. Please write a comment below solution which i have provided. Do not write as the answer :) Happy coding :)Armlet
Comments and answers are different!Noctambulous
B
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.

Biafra answered 28/10, 2016 at 19:33 Comment(0)
E
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)?

Erle answered 14/12, 2016 at 17:2 Comment(0)
U
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.

Ulrike answered 12/10, 2017 at 7:26 Comment(0)
R
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

Railhead answered 7/6, 2017 at 20:0 Comment(0)
P
1

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

Paranoia answered 6/4, 2018 at 14:49 Comment(0)
S
1

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

Sprinkler answered 4/3, 2019 at 7:18 Comment(0)
L
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';

Laundrywoman answered 25/9, 2019 at 7:12 Comment(2)
If UTf-8 not show in android studio bottom bar then ctl+shift+n open LoopView Class then so Bottom BarLaundrywoman
if ISO-8859-1' is bot show then please open LoopView file then show it in bottombarLaundrywoman
N
0

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

Neomaneomah answered 5/9, 2019 at 16:18 Comment(0)
D
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.

Diencephalon answered 8/3, 2020 at 3:54 Comment(0)
P
0

2 CLICK SOLUTION

In the bottom right corner of Android Studio:

1 Click on UTF-8

2 Click on Remove BOM

enter image description here

I guess that this is a new option in Android Studio because none of the other answers mentioned it.

Pyrophotometer answered 28/9, 2023 at 21:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.