Displaying Arabic Text in J2me Using Eclipse
Asked Answered
A

3

3

I am new to J2me, kindly can anybody tell me how can I do below in J2me?

String salam="اَللّٰهُمَّ اِنِّىْ اَسْئَلُكَ رِزْقًاوَّاسِعًاطَيِّبًامِنْ رِزْقِكَ";
byte[] bytes = salam.getBytes("UTF-8");
str1=new String(bytes);
System.out.println("Arabic :"+str1);

it is displaying سلام char like that

I am using Eclipse Indigo Service Release 1.

Autosome answered 6/2, 2012 at 14:1 Comment(6)
If you don't use the same character set for decoding as encoding, you are not going to get the same string in this case. What do you get if the decoding is also "UTF-8" ?Clipclop
@Mat Not possible duplicate, but exact duplicate; this time, however, he provides code for us.Waters
i have delete the perivious oneAutosome
للّٰهÙ?Ù…ÙŽÙ‘ اÙ?Ù†Ù?ّىْ اَسْئَلÙ?ÙƒÙŽ رÙ?زْقًاوَّاسÙ?عًاطَيÙ?ّبًامÙ?نْ رÙ?زْقÙ? This is what i am getting Any Solution.Autosome
str1=new String(bytes, "UTF-8"); will give ?????? ??????? ?????????? ???????????????????????????? ??????Autosome
@user1029637 It is not a good idea to store localized string in java code. What about internationalization? You can read this article.Plafond
S
1

The below code can be use for displaying arabic text in J2ME

String s=new String("\u0628\u06A9".getBytes(), "UTF-8");

where \u0628\u06A9 is the unicode of two arabic letters

Slogan answered 7/2, 2012 at 7:57 Comment(0)
F
2

You should use the a String contructor that allows you to specify the charset with an argument like String(byte[], Charset) (No Charset in J2ME) or String(byte[], String). Otherwise the byte array will be decoded using the platform default which may not be UTF-8.

Example:

 byte[] utf8bytes = ... //Byte array containing UTF-8 as bytes.
 String string = new String(utf8bytes, "UTF-8");
Foley answered 6/2, 2012 at 14:16 Comment(3)
i use it like that str1=new String(bytes, "UTF-8"); same happen ??Autosome
It is possible that what ever console you are using that is displaying System.out does not have glyphs for those code points. What happens if you try to System.out your original String literal?Foley
there's no constructor with Charset in J2ME MIDP String APIVotary
S
1

The below code can be use for displaying arabic text in J2ME

String s=new String("\u0628\u06A9".getBytes(), "UTF-8");

where \u0628\u06A9 is the unicode of two arabic letters

Slogan answered 7/2, 2012 at 7:57 Comment(0)
P
-1

I found the solution :
Window > Preferences > General > Content Types

Chose the type of file you want (Text=> java in your case )

Now paste UTF-8 to Default encoding and click "update".

Pudency answered 15/8, 2012 at 0:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.