i have to work on an open source App, I have cloned the project from the repository but I get a compilation error at this point

 public static HashMap<Character, String> UNICODE_TRANS = new HashMap<Character, String>();
    static {
        UNICODE_TRANS.put('÷', "/");
        UNICODE_TRANS.put('×', "*");
        UNICODE_TRANS.put('÷', "/");
        UNICODE_TRANS.put('×', "*");
        UNICODE_TRANS.put('²', "^2");
        UNICODE_TRANS.put('³', "^3");
        UNICODE_TRANS.put('�', "^4");
        UNICODE_TRANS.put('−', "-");
        UNICODE_TRANS.put('µ', "micro");
        UNICODE_TRANS.put('Ï€', "pi");
        UNICODE_TRANS.put('Π', "pi");
        UNICODE_TRANS.put('€', "euro");
        UNICODE_TRANS.put('Â¥', "japanyen");
        UNICODE_TRANS.put('₤', "greatbritainpound");
        UNICODE_TRANS.put('√', "sqrt");
        UNICODE_TRANS.put('∛', "cuberoot");
        UNICODE_TRANS.put('½', "1|2");
        UNICODE_TRANS.put('â…“', "1|3");
        UNICODE_TRANS.put('â…”', "2|3");
        UNICODE_TRANS.put('¼', "1|4");
        UNICODE_TRANS.put('â…•', "1|5");
        UNICODE_TRANS.put('â…–', "2|5");
        UNICODE_TRANS.put('â…—', "3|5");
        UNICODE_TRANS.put('â…™', "1|6");
        UNICODE_TRANS.put('â…›', "1|8");
        UNICODE_TRANS.put('⅜', "3|8");
        UNICODE_TRANS.put('â…�', "5|8");
    }

that say me Invalid character constant at every line

UNICODE_TRANS...etc

Why i cannot use these character constants. Is there something to set to avoid this compilation issue?

有帮助吗?

解决方案

UNICODE_TRANS.put('÷', "/");

There are two characters in that literal, so it's not a character literal. What was meant was:

UNICODE_TRANS.put('÷', "/");

So what has probably happened is that the source code is saved as UTF-8, but is being interpreted by the compiler (and your text editor) as Windows code page 1252.

To fix the compiler for normal javac you use the flag -encoding UTF-8. The way you specify that for different IDEs and build systems will vary.

It is unfortunate that Java does not have in-file signalling for encoding. You can avoid the problem by ensuring source is pure ASCII, and including non-ASCII characters via escape:

UNICODE_TRANS.put('\u00F7', "/");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top