6

Why does the following code make my Android App crashing?

new String("é".getBytes(StandardCharsets.UTF_8), "UTF8")

or simply

new String("é".getBytes())

How to do this?

Some infos:

Error:

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 build fingerprint: 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: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x5 in tid 18924 (JDWP)

Related question found here: Java Strings Character Encoding - For French - Dutch Locales

------- EDIT:

It happens only in my Android Studio debugger! So when I use this as watch or "evaluate expression". But when I do this in the code and then Log.d(...) it works fine!!! Android Studio 2.1.3

I created an Android Studio Issue for that: https://code.google.com/p/android/issues/detail?id=220366

Community
  • 1
  • 1
Denny Weinberg
  • 2,492
  • 1
  • 21
  • 34
  • please provide more specific logs – Leszek Jasek Aug 18 '16 at 18:50
  • That's all what I have after executing this... – Denny Weinberg Aug 18 '16 at 18:52
  • have you tried another device? – TWL Aug 18 '16 at 19:02
  • It looks for me like platform specific error. Does the app behave the same on emulator? – Leszek Jasek Aug 18 '16 at 19:04
  • Yes, I have it also in my emulator. Nexus 6P API 23 Android 6.0 x86 ---------- Oh interesting! It happens only in my Android Studio debugger! So when I use this as watch or "evaluate expression". But when I do this in the code and then Log.d(...) it works fine!!! – Denny Weinberg Aug 18 '16 at 19:09
  • What if you use `StandardCharsets.UTF_8` too instead of "UTF8"? AFAIK, "UTF-8" is the right name of it – Sergey Glotov Aug 18 '16 at 19:11
  • @Sergey Glotov: It's the same result. Crash. Even "new String("é".getBytes())" does not work. But only in Android Studio! See http://stackoverflow.com/questions/39025153/android-crash-because-of-simple-byte-to-string-operation#comment65402397_39025153 – Denny Weinberg Aug 18 '16 at 19:15

1 Answers1

0
new String("é".getBytes())

It works perfectly for me. I have tested it with android min API 14. Please check, it may occur for any other issue.

Md Samiul Alim Sakib
  • 1,114
  • 12
  • 15
  • I am using Android 6.0.1 CM 13.0-20160813 NIGHTLY on my OnePlus One. It crashed instantly. Even if I enter it in the Android Studio debugger. MinAPI is set to 10. – Denny Weinberg Aug 18 '16 at 18:50