-1

I'm having a big problem with my computer, as I try to compile source code made in Java language, hence a great frustration:

The variable of type String is poorly read and interpreted by the compiler and prints squares instead of special characters.

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Name:");
        String name = sc.nextLine();
        System.out.println(name);
    }   
}

Result:

enter image description here

My attempts were:

  • Change the "netbeans.conf" configuration file in the IDE's files folder located in File Explorer

  • Install multiple versions of NetBeans IDE to see if this problem occurs in all versions. Yes, it occurs in all versions and I have tried all the program's configuration alternatives

  • Uninstall and Install the version of the JDK on my computer and to ensure I also installed the JRE on my machine to see if the problem was resolved after installing all these programs. Nothing resolved and without success. The problem continued to compile this little code in the IDE.

With this problem, I can't:

  • Create applications with databases (MySQL + JDBC) in the Java language, because the parameters of the PreparedStatement object do not recognize the special characters of the String due to this problem

enter image description here

  • Create Java applications in general, because if this problem occurs that, in my opinion, seems like an impossible solution to be solved on my computer, how will I continue to create systems with this special character recognition error?

  • Compile source code on my computer, as the compiler does not recognize special characters like ç, á, ã, â, í, among others and instead of displaying them in the output, squares appear as you saw in the previous image.

Was it some configuration that was left behind or is it a solution that I am not able to develop to fix this problem? And if so, what would be the best explanation for solving this problem? Will it be necessary to contact the technician for more information?

pe.Math
  • 89
  • 1
  • 7
  • Both the Scanner and System.out can be modified to work with different charsets. It's not a complete answer, but might point you in the right direction? The command chcp can be used to find out the charset used by the console. – Tigris Dec 12 '20 at 16:12
  • Your solution seems to be very interesting, is that in fact I wanted to find a solution to solve this error and the possibility of configuring the character set seems to be a very possible explanation for this problem. I typed the command chcp in cmd and Active code page appeared: 850. I'm not sure what that means, but could you provide a clearer answer according to what you said? Perhaps your more detailed explanation of what you said earlier may help to resolve this case. – pe.Math Dec 12 '20 at 17:21
  • 1
    https://en.wikipedia.org/wiki/Code_page_850 – Tigris Dec 14 '20 at 09:37
  • 1
    I'm neither very familiar with charsets or with netbeans, so I'm not of that much more help. 850 (https://en.wikipedia.org/wiki/Code_page_850) seems like it contains most typical special characters, so that shouldn't be the problem. My next step if I was debugging this problem would be to add a breakpoint and see if the text inside the variable String name looked correct. This would help determine if the problem is inside the Scanner object or the System object. – Tigris Dec 14 '20 at 09:43
  • 1
    Actually, I also found this, that might help you too: https://stackoverflow.com/questions/23709515/netbeans-java-console-encoding-utf-8-and-umlauts – Tigris Dec 14 '20 at 10:08

1 Answers1

0

I am grateful that @Tigris helped me with this problem, which actually when I went to check I ended up making a storm in a glass of water. The @Tigris solution in the comments gave me an idea that became immediate when I analyzed the error I was giving with the answer he initially gave me.

The problem was simple, it was basically a character encoding error in the IDE's terminal that was solved with the line I typed in CMD:

chcp 1252

This solution is related to the link at the end of the comments and in it you notice that the explanation of the post indicates that the problem can be solved with a simple line of code that sets a system property.

But after solving this problem and analyzing the link that @Tigris shared here in the comments, I was thinking: If my problem hadn’t solved and still insisted on showing special characters in an unreadable way, then I would have to insert the answered line of code posting on all my projects?

That is why it is always good to check the device's character string right when it comes from the factory or even a repair, because depending on the occasion when this display problem of special characters can change the database that the user is working in case be a developer or even to build an API or Webservice for a client without paying attention to these details of textual stress, which can cause inconvenience and headaches when finishing a project in any IDE that is installed on the computer.

pe.Math
  • 89
  • 1
  • 7