×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    1

    Unicode Character display

    Hi,

    I have developed a J2ME mobile application which downloads the data from the webserver and displayes to the mobile user.

    Now some of the data contains finnish chracters and others in english. When I try to display such data item in TextField object it displays some junk characters.

    Can anyone guide me how to solve this problem?
    i.e display the data in correct character set.

    - Dipak Mehta

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    21
    Hi
    I was just about to put a similar post up myself. Do the "junk" characters look anything like this:

    ?¨¤ l'arri?¨¨re

    (though on the actual phone the '?' is more like a rectangular box)

    I was under the impression that the Java enabled phones display UTF-8. The text that I am reading in is definitely UTF-8 and displays correctly in all the emulators. It is only when I run the application on the phone that I get these junk characters.

    If someone could help that would be really appreciated as I too am trying to figure out the same problem.

    Thanks
    Alex

  3. #3
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395
    I would guess that you are reading UTF-8, but the phone is displaying unicode - they're not the same thing. Unicode uses 16 bits per character. UTF-8 encodes unicode into 8 bit bytes, using one, two or three bytes per character.

    You are converting bytes read from the network stream into one character each. This works fine for characters 0 to 127, which are encoded in UTF-8 as one byte. But other characters are encoded in multi-byte formats, so appear as a sequence of two or three incorrect characters.

    You may be able to get the String object to translate bytes correctly, if the device supports UTF-8 encoding. (I would guess it is translating from ISO-8859-1 by default). Otherwise, you can find a description of UTF-8 in the API documentation under java.io.DataInput.readUTF().

    You might also want to check what encoding you are receiving, by looking at the charset tag in the content-type header field.

    Graham.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •