Intellij IDEA: "unmappable character for encoding UTF-8" compiling ISO-8859-1 files
Asked Answered
I

6

21

I have a mixed-encoding source tree and I'm getting the warning above for some of my source files. I managed to sucessfully set the encoding for those files to ISO 8859-1 and, after invalidating IDEA's caches, they now display correctly in the editor. However, when I compile, I still get the error message.

Production builds use ant and it's not an issue there, but it means I can't "make" in the IDE. Is there a way to get IDEA to compile these correctly, or failing that, drop the error down to a warning?

Insensible answered 9/9, 2011 at 18:1 Comment(3)
I have no idea about IDEA, but why do you need a mixed-encoding source tree? Wouldn't converting all the files to UTF-8 make the life easier?Lambency
The files in question have to do with regex matching in foreign-language data with known encodings. It's easier and less error-prone to write the regex in the encoding you're matching against... or so I assume. (I'm new to this code base.)Insensible
When the strings are in memory, they are UTF-16 anyway, independent of the encoding the files were in (assuming you compiled them right). So while I can see why these files were created in these encodings, there is nothing speaking against converting them now. (Of course, you can also try to get the IDEA bug fixed.)Lambency
W
38

I solved this issue adding this property in IntelliJ option panel Compiler/Java Compiler :

Additional command line parameters : -encoding ISO-8859-1

Wetzel answered 7/10, 2012 at 7:41 Comment(0)
O
4

I have UTF-8 encoding in encoding.xml as follows, but still not working. keeps getting error "Error: java: error: unmappable character (0xFE) for encoding UTF-8"

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
    <file url="file://$PROJECT_DIR$" charset="UTF-8" />
    <file url="PROJECT" charset="UTF-8" />
  </component>
</project>
Overlord answered 28/9, 2017 at 7:20 Comment(0)
G
3

Looks like a known bug.

Gemagemara answered 9/9, 2011 at 18:41 Comment(5)
I've got a single-module project, so if that bug is accurately reported, I think I'm looking at something different.Insensible
You can file a separate issue and attach a sample project so that we can investigate it.Gemagemara
It seems like a bug. Our project is UTF-8, the file in question is on UTF-8 (checked with Notepad++) but Intellij complains about Cp1252. Totally a bugCopyist
@HenriquedeSousa Please report at youtrack.jetbrains.com/newIssue?project=IDEA with a sample project to reproduce.Gemagemara
As soon as I invalidate caches and build the entire project, the bug went away. Oh well, sorry :)Copyist
P
3

If you are using Intellij, the fastest way for me was:

File -> File Properties-> File encoding

and choose the one you want, in this case ISO-8859-1.

Persuader answered 21/1, 2014 at 10:36 Comment(0)
D
0

Solution tested in IntelliJ 2019.3

Open the troublesome file. Go to File -> File Encoding. (You also have a quick option at the bottom right) Select the encoding you want. In my case it was UTF-8. Click on Convert when it prompts you if you want to convert the file in new encoding and overwrite the contents.

Try to compile. You should be able to compile fine.

Diplopia answered 8/3, 2021 at 11:49 Comment(0)
L
0

Change "Javac" to "Eclipse" in Java Compiler

I met the same error message, and tried the methods above that did not work well for me.

But I change the setting in Compiler. In the panel "Use compiler", click and choose Eclipse.

Done.

Linwoodlinz answered 27/9, 2023 at 12:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.