0

I have this assignment:

String msg = "El código QR ya no es válido";

when debugging, this is displayed:

El código QR ya no es válido

what may be the problem?

EDIT:

when that text comes from a Web Server, which sends texts using UTF-8 encoding, string is assigned correctly. The problem is only when assigning a string directly to a String variable.

Thanks Jaime

jstuardo
  • 3,901
  • 14
  • 61
  • 136
  • Java compiler accepts a source code encoding attribute - make sure that's set correctly. If that's not it, then it's the encoding of whatever mechanism you're using to display the string. – TrogDor Aug 26 '20 at 16:47
  • 2
    The source file encoding in the text editor or IDE does not match the compiler encoding. What text editor / IDE are you using and how are you compiling the code? – Joni Aug 26 '20 at 16:51
  • @Joni It is an Android development. IDE is Android Studio and file is in UTF-8 enconding, I have just checked. Furthermore, the problem is only when assigning a String directly. When I retrieve a string from a call to a Web Service (which sends the text using UTF-8 format) it works. – jstuardo Aug 26 '20 at 17:02
  • This is an IDE or compiler configuration issue. There was a very similar question yesterday https://stackoverflow.com/questions/63580725/thai-script-seems-to-lose-utf-8-encoding-in-java-for-each-loop/63580816 – Joni Aug 26 '20 at 17:30
  • You need to tell your compiler that the file is using the UTF-8 encoding. – VGR Aug 26 '20 at 17:35
  • @Joni It is similar, but he started with an array of bytes. That could suggest I need to get a bytes array and then create a new string from it. It seems so tricky, doesn't it? I have never had this problem, neither with C# nor PHP. In this case of Java, file is already encoded as UTF-8. Will it also depends on how the compiler is configured? Anyway, I have forced compiler to be in UTF-8 but no solution. – jstuardo Aug 26 '20 at 18:23
  • @Joni I have found this with respect to IDE: `The encoding used to compile your project is specified in the build.gradle files. The default, which is used when no specific encoding is specified, is UTF-8`. So, I confirmed both file and compiler is in UTF-8. What else can I try? – jstuardo Aug 26 '20 at 18:28
  • I have found that this problem only exists for a class library project. If that assignment is made inside the Android activity, it works. – jstuardo Aug 26 '20 at 18:35

0 Answers0