"Unmappable Character for Encoding Utf-8" Error

Error: unmappable character for encoding UTF8 during maven compilation

Configure the maven-compiler-plugin to use the same character encoding that your source files are encoded in (e.g):

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>

Many maven plugins will by default use the "project.build.sourceEncoding" property so setting this in your pom will cover most plugins.

<project>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
...

However, I prefer setting the encoding in each plugin's configuration that supports it as I like to be explicit.

When your source code is compiled by the maven-compiler-plugin your source code files are read in by the compiler plugin using whatever encoding the compiler plugin is configured with. If your source files have a different encoding than the compiler plugin is using then it is possible that some characters may not exist in both encodings.

Many people prefer to set the encoding on their source files to UTF-8 so as to avoid this problem. To do this in Eclipse you can right click on a project and select Properties->Resource->Text File Encoding and change it to UTF-8. This will encode all your source files in UTF-8. (You should also explicitly configure the maven-compiler-plugin as mentioned above to use UTF-8 encoding.) With your source files and the compiler plugin both using the same encoding you shouldn't have any more unmappable characters during compilation.

Note, You can also set the file encoding globally in eclipse through Window->Preferences->General->Workspace->Text File Encoding. You can also set the encoding per file type through Window->Preferences->General->Content Types.

Android Studio : unmappable character for encoding UTF-8

I had the same problem because there was files with windows-1251 encoding and Cyrillic comments. In Android Studio which is based on IntelliJ IDEA you can solve it in two ways:

a) convert file encoding to UTF-8 or

b) set the right file encoding in your build.gradle script:

android {
...
compileOptions.encoding = 'windows-1251' // write your encoding here
...

To convert file encoding use the menu at the bottom right corner of IDE. Select right file encoding first -> press Reload -> select UTF-8 -> press Convert.

Also read this Use the UTF-8, Luke! File Encodings in IntelliJ IDEA

ant: warning: unmappable character for encoding UTF8

Try to change file encoding of your source files and set the Default Java File Encoding to UTF-8 also.

For Ant:

add -Dfile.encoding=UTF8 to your ANT_OPTS environment variable

Setting the Default Java File Encoding to UTF-8:

export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8

Or you can start up java with an argument -Dfile.encoding=UTF8

error: unmappable character for encoding UTF-8

It sounds like you have two options:

  • Call the generator using a command-line parameter to generate UTF-8 instead of whatever it's using by default. (You haven't said where this file actually comes from, but I assume the generation is under your control somewhere...)
  • Change how Netbeans handles the file, telling it what encoding it's really in

Personally I'd favour the first option if possible - UTF-8 is a nice "everything supports it" encoding

unmappable character for encoding warning in Java

Use the "\uxxxx" escape format.

According to Wikipedia, the copyright symbol is unicode U+00A9 so your line should read:

String copyright = "\u00a9 2003-2008 My Company. All rights reserved.";

Android Studio - Unmappable character for encoding UTF-8

Adding the following to build.gradle solves the problem :

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

“Unmappable character for encoding UTF-8” error for IDEA IntelliJ while compiling java files

In IDEA IntelliJ
Go to File --> Settings --> Editor --> File Encodings

Select UTF-8 for Global and Project Encoding, solved my problem.

Sample Image



Related Topics



Leave a reply



Submit