Search code examples
javaencodingutf-8ascii

"unmappable character for encoding" warning in Java


I'm currently working on a Java project that is emitting the following warning when I compile:

/src/com/myco/apps/AppDBCore.java:439: warning: unmappable character for encoding UTF8
    [javac]         String copyright = "� 2003-2008 My Company. All rights reserved.";

I'm not sure how SO will render the character before the date, but it should be a copyright symbol, and is displayed in the warning as a question mark in a diamond.

It's worth noting that the character appears in the output artifact correctly, but the warnings are a nuisance and the file containing this class may one day be touched by a text editor that saves the encoding incorrectly...

How can I inject this character into the "copyright" string so that the compiler is happy, and the symbol is preserved in the file without potential re-encoding issues?


Solution

  • 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.";