Android encoding issue

I have the following line:

String textEncoding = ((payload[0] & 128) == 0) ? "UTF-8" : "UTF-16";

Both options: “UTF-8” and “UTF-16” are in “Red”, representing an error with “Cannot resolve character”.

I'm not sure what to do with this, I'm new to Android, and I'm not sure if there is anything specific that I need to do so that Android Studio finds out what they are. Suggestions are welcome.

Edit: previous assignment

byte[] payload = record.getPayload();

        // Get the Text Encoding
        String textEncoding = ((payload[0] & 128) == 0) ? "UTF-8" : "UTF-16";
+4
source share
3 answers

Before this assignment, make sure that you do not have an immutable string constant, that is, unpaired ". For example, the following will reproduce your problem:

"String textEncoding = ((payload[0] & 128) == 0) ? "UTF-8" : "UTF-16";
+2
source

You must replace it with:

String textEncoding;
if ((payload[0] & 128) == 0) textEncoding = "UTF-8";
else textEncoding = "UTF-16";
+1

.

.

createXMLStreamWriter ( OutputStream, )

0
source

All Articles