Question

I have an issue when displaying strings received from a server in a JTable. Some specific characters appear as little white squares instead of "é" or "à" etc. I tried a lot of things but none of them fixed my problem. I'm working with Eclipse under Windows. The server was developped using Visual Studio 2010. The server sends an XML file using tinyXML2, the client uses JDom to read it. The font used is "Dialog". The server takes the strings from an Oracle database.

I assume this is an encoding problem, but I haven't been able to fix it yet.

Does anyone have an idea ?

Thx

Arnaud

EDIT : As requested, this is how I use JDom

public static Player fromXML(Element e)
{       
    Player  result  = new Player();
    String  e_text  = null;

    try
    {
        e_text = e.getChildText(XMLTags.XML_Player_playerId);
        if (e_text != null) result.setID(Integer.parseInt(e_text));

        e_text = e.getChildText(XMLTags.XML_Player_lastName);
        if (e_text != null) result.setName(e_text);

        e_text = e.getChildText(XMLTags.XML_Player_point_scored);
        if (e_text != null) result.addSpecial(STAT_SCORED, Double.parseDouble(e_text));

        e_text = e.getChildText(XMLTags.XML_Player_point_scored_last);
        if (e_text != null) result.addSpecial(STAT_SCORED_LAST, Double.parseDouble(e_text));
    }
    catch (Exception ex) {
        ex.printStackTrace();
    }

    return result;
}

    public static Document load(String filename) {
    File XMLFile = new File(CLIENT_TO_SERVER, filename);
    SAXBuilder sxb = new SAXBuilder();
    Document document = new Document();
    try
    {
         document = sxb.build(new File(XMLFile.getPath()));
    } catch(Exception e){e.printStackTrace();}

    return document;
}
Was it helpful?

Solution

read the file using correct encoding, something like:

document = sxb.build(new BufferedReader(new InputStreamReader(new FileInputStream(XMLFile.getPath()), "UTF8")));

Note: 1. 1st determine which char encoding used in that file. specify that charset instead of UTF8 above.

  1. Incase encoding is not known or it's being generated from various systems with different encoding, you may use 'encoding detector library of Mozilla'. @see https://code.google.com/p/juniversalchardet/

  2. need to handle UnsupportedEncodingException

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top