5

我对 Java 和 Android 都很陌生。

我正在尝试用俄语字符初始化字符串

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

但是,当我打开调试器时,我看到了一些奇怪的chars

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

文件是 UTF-8 格式,所以这不是问题我也尝试设置俄罗斯语言环境

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

这无济于事。

PS:我使用 Android Studio 作为 IDE - 可能这就是问题所在

4

1 回答 1

5

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.
于 2013-07-25T21:39:07.407 回答