0

I have a GUI where i try to convert a EBCDIC String into Hex, but i am getting the NumberforamtException.

ebcdichex.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ausgabe6.setText("");
            String hexadecimal3 = eingabe4.getText().replace("\n", "");
            byte[] chars2;

            try {
                chars2 = hexadecimal3.getBytes("IBM-273");
                StringBuilder hexa2 = new StringBuilder();
                for(int i = 0;i<chars2.length;i++){
                    byte[] b = {(byte) Integer.parseInt(""+chars2.toString(),16)};      
                    hexa2.append(b);
                }
                ausgabe6.append(hexa2.toString());
            }
         catch (UnsupportedEncodingException e1) {

            e1.printStackTrace();
        }
        }
    });

Exception:

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For 
input string: "[B@1d05c81"

Does anyone know where my fault is?

Starlight
  • 5
  • 1
  • 6
  • The `toString` method on an array doesn't give you what you expect, try `byte[] b = {(byte) Integer.parseInt(new String(chars2),16)}; ` (also see : https://stackoverflow.com/questions/4479683/java-arrays-printing-out-weird-numbers-and-text) – Arnaud Jan 24 '18 at 08:28
  • Hmm this didnt work for me. I still get the NumberFormatException error:/ my input was "A" but the console says my input would be "Á" – Starlight Jan 24 '18 at 15:24

0 Answers0