0

I get compile error when typing javac Main.java in terminal and the message i get is:

.\Constants.java:32: error: unmappable character (0x9D) for encoding windows-1252.

I know it caused by this bit of code:

public static final String[] UNICODE_TEXT = {
      "― ", // CELL_EMPTY
      "✗ ", // CELL_X
      " ", // CELL_O
      "  ", // CELL_INVALID
  };

It is the "✗ " and the " " that causes this problem since they are special characters. I don't want to change the code since it was provided by the course. How can I compile this?

Muja
  • 1
  • 1
  • 2
  • 4
    Possible duplicate of ["unmappable character for encoding" warning in Java](https://stackoverflow.com/questions/464874/unmappable-character-for-encoding-warning-in-java). Adding `-encoding UTF-8` to your javac command ought to fix it – Aaron Sep 22 '19 at 13:10
  • I tried using javac -encoding ISO-8859-1 file_name.java. the compile did work however other normal characters were wrongly encoded – Muja Sep 22 '19 at 13:21
  • 1
    @Muja If you plan to use "ISO-8859-1" as the argument for the `-encoding` parameter, you have to save the source file in that format (and not ins "windows-1252"). – Progman Sep 22 '19 at 13:28
  • Don’t use ISO-8859-1 or windows-1252. Your file is a UTF-8 file. “” is [U+1D442 MATHEMATICAL ITALIC CAPITAL O](http://www.fileformat.info/info/unicode/char/1d442/index.htm). In UTF-8, its bytes are: 0xf0 0x9d 0x91 0x82. That is where the 0x9D comes from. – VGR Sep 22 '19 at 16:06

1 Answers1

0

Do set your Java Encoding correctly by creating the environment variable called JAVA_TOOL_OPTIONS and set it to -Dfile.encoding=UTF8

Source: https://stackoverflow.com/a/23399955/9758687

Coden
  • 2,579
  • 1
  • 18
  • 25