Android崩溃是因为简单的字节到字符串操作

Den*_*erg 6 android

为什么以下代码会导致我的Android应用崩溃?

new String("é".getBytes(StandardCharsets.UTF_8), "UTF8")
Run Code Online (Sandbox Code Playgroud)

或者干脆

new String("é".getBytes())
Run Code Online (Sandbox Code Playgroud)

这该怎么做?

一些信息:

  • "é"是字节(195 169)是(U + 00E9)(在此处找到:http://www.utf8-chartable.de/unicode-utf8-table.pl?utf8 = dec )
  • java中的字节始终是有符号的,因此(195 169)是(-61 -87)(信息:将无符号字节转换为有符号字节)
  • 我在OnePlus One上使用Android 6.0.1 CM 13.0-20160813.它瞬间崩溃了.即使我在Android Studio调试器中输入它.
  • 如果我使用"StandardCharsets.UTF_8"它不起作用

错误:

08-18 20:30:04.877 18914-18924/com.nextwebart.senego W/google-breakpad:### ### ### ### ### ### ### ### ### ### ### ### ### 08-18 20:30:04.877 18914-18924/com.nextwebart.senego W/google-breakpad:Chrome构建指纹:08-18 20:30:04.877 18914-18924 /com.nextwebart.senego W/google-breakpad:4.2.8 08-18 20:30:04.877 18914-18924/com.nextwebart.senego W/google-breakpad:70 08-18 20:30:04.877 18914-18924 /com.nextwebart.senego W/google-breakpad:### ### ### ### ### ### ### ### ### ### ### ### ## #08-18 20:30:04.877 18914-18924/com.nextwebart.senego A/libc:致命信号11(SIGSEGV),代码1,故障地址0x5 in tid 18924(JDWP)

相关问题在这里:Java字符串字符编码 - 法语 - 荷兰语语言环境

-------编辑:

它只发生在我的Android Studio调试器中!所以当我用它作为手表或"评估表达"时.但是当我在代码中执行此操作然后Log.d(...)它工作正常!Android Studio 2.1.3

我为此创建了Android Studio问题:https://code.google.com/p/android/issues/detail?id = 220366

Md *_*kib 0

new String("\xc3\xa9".getBytes())\n
Run Code Online (Sandbox Code Playgroud)\n\n

它非常适合我。我已经使用 android min API 14 对其进行了测试。\n请检查,可能会出现任何其他问题。

\n