I cannot correctly view my UTF8 line in AndroidSutdio debugging or android layouts. below is my code:
String test1 = "hélǐ";
Results: test1 = hà © lÇ
test1 It seems like reading my UTF8 ANSI encoded string in notepad ++. However, if I directly bind it to an XML layout (instead of the Button.setHint () method), I can correctly see hélǐ.
UPDATE 1: thanks Jon Skeet for pointing test1.lenght () = 6 and not 4, so this is not a display problem. UPDATE 2: thanks Joop Eggen for pointing out that “h \ u00e9l \ u012d” will return the correct answer UPDATE 3: I have a copy, paste my code into an equivalent Android project on eclipse and it works great. therefore, the problem should be related to AndroidStudio. UPDATE 4: added the variable JAVA_TOOL_OPTIONS = -Dfile.encoding = UTF-8 to force javac using this command, but without affecting the result. UPDATE 5: I installed AndroidStudio on ubuntu and copied my code, and it works fine too. But how to fix it on AndroidStudio Windows? (unfortunately, I need to use windows)
Has anyone ever encountered this problem before? how to fix without using code \ u Thanks
Note:
- I am using AndroidStudio
- in my Javac and Android DX complier I added -encoding utf8
- in my AndroidStudio all file encodings are set to utf8 (and I see utf8 at the bottom right).
- Charset.defaultCharset () return utf8
- InputStreamReader.getEncoding () return utf8
- In my xml layout there is a utf8 flag at the top
- Notepad ++ reads my copy / paste "hélǐ" with utf8 encoding correctly.
source share