Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File is saved in UTF-8 but strange symbols in Russian language

I am quite new to both Java and Android.

I am trying to initialize String with russian chars

    lesson.addUnit(new NounUnit("Schiff", "Корабль", NounUnit.Gender.NEUTRAL));
    lesson.addUnit(new NounUnit("Tafel", "Доска, панель", NounUnit.Gender.FEMININUM));
    lesson.addUnit(new NounUnit("Lineal", "Линейка чертежная", NounUnit.Gender.NEUTRAL));

However when I open my debugger I saw some strange chars

[–,ö,–,æ,—,Ä,–,∞,–,±,–,ª,—,å] instead of Корабль

File is in UTF-8 format so this is not an issue I also tried to set russian locale

    Locale locale = new Locale("ru");
    Locale.setDefault(locale);

This does not help.

PS: I am using Android Studio as IDE - probably this is the issue

like image 437
Georgy Buranov Avatar asked Jul 25 '13 21:07

Georgy Buranov


Video Answer


1 Answers

Often much is misleading, hence the following steps:

  1. You can check .java file encoding with an editor like the free JEdit.
  2. Also the compiler encoding must be set, via the IDE or with javac -encoding UTF-8.
  3. Try "\u041a\u043e\u0440\u0430\u043b\u044c". This is an editor independent representation of "Корабль", and lets you see whether the .java was encoded right when running.
like image 189
Joop Eggen Avatar answered Sep 22 '22 16:09

Joop Eggen