microedition.encoding problem

Hello,

My Server transmits cyrillic strings to my midlet. On emulator everything is ok, because it seems it takes the default locale and encoding from the PC, but when I installed the midlet on my device, strings are not represented correctly. My phone supports Cyrillic.

Can someone help me - I found that I should modify the microedition.encoding property, but it seems not to help .... or may be I didn't modified it correctly.

Does anyone knows solution? I'm frustrated because my new project has to start on 1st Sep, and now I have such critical problem when I installed the software on real devices :(

Appreciate any help.

Peter

[675 byte] By [the_one-seena] at [2007-10-3 3:34:38]
# 1
you may find something here http://java.sun.com/j2me/docs/wtk2.2/docs/UserGuide-html/internationalization.html#wp6947
suparenoa at 2007-7-14 21:29:13 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
I am using DataInput/OutputStreams with appropriate methods writeUTF readUTF for String objects and everything works fine. -Tom
TomToma at 2007-7-14 21:29:13 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3

Hi ,

In fact the server sends sequence of bytes, which is read in the midlet with the socket read method. After, I just try to create String object with the received data, but it fails with unreadable characters when ran on real device .... but on emulator the characters are perfect, because my win encoding is Cp1251 and the emulator takes it by default.

I saw String class accepts also optional parameter for encoding, but I cannot find anywhere the supported encodings from MIDP. What I just tried that if you make String temp = new String( ...., ISO-8859-5), or

ISO8859-5, or Cp1251), it throws runtime exception when ran on real device. So, my hint now is to understand the exact names of the encoding supported from MIDP (which obviously differs from the standard encoding names), or to find how to set microedition.encoding with appropriate name.

For the microedition.encoding, I changed it in the property file but it didn't helped when installed on real device. In fact, after build, I didn't find this parameter in the manifest file, which makes me think it is used by WTK only for emulation, but is not bound in the jar file.

the_one-seena at 2007-7-14 21:29:13 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4

you did :String str = new String(bytesArray, "Cp1251");

?

did you try to use the setRequestProperty(String, String) with your HttpConnection onject like that:c.setRequestProperty("Content-Language", "Cp1251");

?

Message was edited by:

supareno

suparenoa at 2007-7-14 21:29:13 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5

I use sockets, not HTTP connection object.

First, I read the data:

while (count >=0 && total < lenToReceive.intValue()) {

count = is.read(temp, total, lenToReceive.intValue() - total);

if (count <= 0) {

break;

}

total += count;

}

Then, I parse the byte array

paramName = new String(temp, offset, i-offset);

where paramName is String object. On emulator this works just fine and paramName contains readable characters.

I tried to do this:

paramName = new String(temp, offset, i-offset, "Cp1251"); but it throws runtime error due to Cp1251 parameter ...

the_one-seena at 2007-7-14 21:29:13 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 6
So only help is to change encoding of incomming data, I guess.Can't you send data in UTF-8 encoding? That should be supported also on devices.-Tom
TomToma at 2007-7-14 21:29:13 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 7
or try with an HttpConnection
suparenoa at 2007-7-14 21:29:13 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 8
You can't modify the system property encoding through your application; try and see if the encoding returned by the property is the one which knows how to read your characters; if it isn't you have to see what you can do to change that from the phone's settings if you can.Mihai
Printisora at 2007-7-14 21:29:13 > top of Java-index,Java Mobility Forums,Java ME Technologies...