In simulator I can run my app, but on device with Jelly Bean OS I get a crash. Any idea why?
07-04 12:51:57.576 18243-18279/com.j4nos.moviebuffs6 E/AndroidRuntime: FATAL EXCEPTION: Thread-7940
java.lang.NoClassDefFoundError: java.nio.charset.StandardCharsets
at com.j4nos.moviebuffs6.Utility$1.run(Utility.java:52)
at java.lang.Thread.run(Thread.java:838)
This is the line I need character encoding:
byte[] out = str.getBytes(StandardCharsets.UTF_8);
StandardCharsets
was added in API Level 19. It is not available for any of the Jelly Bean versions of Android.
There are various overloaded .getBytes()
method is declared in String
Class.
public void getBytes(int, int, byte[], int);
public byte[] getBytes(java.lang.String) throws java.io.UnsupportedEncodingException;
public byte[] getBytes(java.nio.charset.Charset);
public byte[] getBytes();
You can use any of it. but you should try this..
byte[] out = str.getBytes("UTF-8");
instead of
byte[] out = str.getBytes(StandardCharsets.UTF_8);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With