You Are Here:

Community: Developer Discussion Boards

Reply « Previous Thread | Next Thread »

#1 Old Unhappy illegal unicode escape in j2me when i splite string... - 2009-01-16, 08:22

Join Date: Dec 2008
Posts: 122
chaoraksa
Offline
Regular Contributor
Hi all!
I have two questions to ask.
- 1).I need to splite one string into array in order to use and that string is unicode(Khmer Unicode)Below is Splite Method in j2me using Netbean v6.1:
private String[] split(String original, String separator) {
Vector nodes = new Vector();

// Parse nodes into vector
int index = original.indexOf(separator);
while (index >= 0) {
nodes.addElement(original.substring(0, index));
original = original.substring(index + separator.length());
index = original.indexOf(separator);
}
// Get the last node
nodes.addElement(original);

// Create splitted string array
String[] result = new String[nodes.size()];
if (nodes.size() > 0) {
for (int loop = 0; loop < nodes.size(); loop++) {
result[loop] = (String) nodes.elementAt(loop);
}
}
return result;
}

And when i call that Method to use like this: String[] Test=split("\u1780\u17B6\u1780\u17B7","\u");

and then i got an error message like this ( Illegal Unicode Ecapse ).
2). I wonder can i read sms message from inbox using j2me. I search already in forum but they some said no and some said yes and which one is true and if have what to do.
3). Anything can i write plug in-- in Write message -- using J2ME like Keyboad layout.

Please any help any recommand I need it emergency.
Last edited by chaoraksa : 2009-01-16 at 09:22.
Reply With Quote

#2 Old Thumbs up Re: illegal unicode escape in j2me when i splite string... - 2009-01-16, 08:33

Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
Send a message via Skype™ to raj_J2ME
raj_J2ME's Avatar
raj_J2ME
Offline
Forum Nokia Champion
Quote:
Originally Posted by chaoraksa View Post
Hi all!
I have two questions to ask.
- 1).I need to splite one string into array in order to use and that string is unicode(Khmer Unicode)Below is Splite Method in j2me using Netbean v6.1:
private String[] split(String original, String separator) {
Vector nodes = new Vector();

// Parse nodes into vector
int index = original.indexOf(separator);
while (index >= 0) {
nodes.addElement(original.substring(0, index));
original = original.substring(index + separator.length());
index = original.indexOf(separator);
}
// Get the last node
nodes.addElement(original);

// Create splitted string array
String[] result = new String[nodes.size()];
if (nodes.size() > 0) {
for (int loop = 0; loop < nodes.size(); loop++) {
result[loop] = (String) nodes.elementAt(loop);
}
}
return result;
}

And when i call that Method to use like this: String[] Test=split("\u1780\u17B6\u1780\u17B7","\u");

and then i got an error message like this ( Illegal Unicode Ecapse ).
2).I wonder can i read sms message from inbox using j2me. I search already in forum but they some said no and some said yes and which one is true and if have what to do.

Please any help any recommand I need it emergency.

Hi,
1.have to check the code,
2.You can not read the SMS which reside in the inbox..and you want to read the same..not possible in J2ME,however it can be done in symbian c++,

However you can read the sms that comes on the particular port using Java ME


Thanks

R a j - The K e r n e l
Reply With Quote

#3 Old Re: illegal unicode escape in j2me when i splite string... - 2009-01-16, 11:46

Join Date: Dec 2008
Posts: 122
chaoraksa
Offline
Regular Contributor
Thanks!
Does it have problem with splite code? and if i use particular port, so i need to design my own Inbox and other thing right? so let give me the way to do that.
Last edited by chaoraksa : 2009-01-16 at 11:51.
Reply With Quote

#4 Old Wink Re: illegal unicode escape in j2me when i splite string... - 2009-01-16, 12:04

Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
Send a message via Skype™ to raj_J2ME
raj_J2ME's Avatar
raj_J2ME
Offline
Forum Nokia Champion
Hi,
Not get the time for the split function checking..

In order to read the SMS on the particular port,firstly sms will never go to the inbox,if unfortunately it went to the inbox,you will be like un-helpfull,

Now how to read the sms coming form the specific port,
@ You have already send the sms on the port lets say 50,000,
@ Then on the same port you will wait for the sms to come,
@ As soon as it will come,then your sms listener will read the sms,

if you want to listen and read the sms just follow the code,
package Raj.SMS;

import java.io.IOException;
import java.util.Vector;
import javax.microedition.io.Connector;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.wireless.messaging.BinaryMessage;
import javax.wireless.messaging.Message;
import javax.wireless.messaging.MessageConnection;
import javax.wireless.messaging.MessageListener;
import javax.wireless.messaging.TextMessage;

//import com.sun.perseus.model.Set;

public class SmsReceive implements Runnable, MessageListener
{

MessageConnection smsconn;
Thread thread;
Message msg;
Image image;
SMSCanvas smsCanvas;
public static Vector smsData;

public void startReceiving(String portDest, SMSCanvas canvas)
{
smsCanvas = canvas;
String smsConnection = "sms://:" + portDest;
if (smsconn == null)
{
try
{
smsconn = (MessageConnection) Connector.open(smsConnection);
smsconn.setMessageListener(this);
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
thread = new Thread(this);
thread.start();
}
static String string = null;

public void run()
{
try
{
msg = smsconn.receive();

if (msg != null)
{
if (msg instanceof TextMessage)
{
string = ((TextMessage) msg).getPayloadText();

}
else
{
byte[] data = ((BinaryMessage) msg).getPayloadData();
string = new String(data);
System.out.println("SmsReceive.run()" + new String(data));
}
ParseData(string);

smsconn.close();
smsconn=null;
}
}
catch (IOException e)
{
System.out.println("Exception caught .."+e.toString());
}
}
public String statusOFMessage = null;
public static String myTotalFare = null;
public void ParseData(String string)
{

statusOFMessage = string.substring(0,1);
System.out.println("statusOFMessage- "+statusOFMessage);
if(statusOFMessage.equals("0"))
{
int beginIndex = 1, endIndex = 0;
smsData = new Vector();
for (int i = 0; i < string.length(); i = endIndex)
{
endIndex = string.indexOf(",", beginIndex);
if (endIndex < 0)
{
endIndex = string.length();
smsData.addElement(string.substring(beginIndex, endIndex));
break;
}
smsData.addElement(string.substring(beginIndex, endIndex));
beginIndex = endIndex + 1;
}
if(smsCanvas.isAskiingForRoutesSMS)
{
String string2;
GPRSDataSender.ChoiceID = new String[smsData.size()];
GPRSDataSender.RouteInfo = new String[smsData.size()];
GPRSDataSender.TotalFare = new String[smsData.size()];
for (int i = 0; i < smsData.size(); i++)
{

string2 = smsData.elementAt(i).toString();
GPRSDataSender.ChoiceID[i] = "" + (i + 1);
GPRSDataSender.RouteInfo[i]=string2.substring(string2.indexOf("#", 0)+1, string2.indexOf("$", 0));
GPRSDataSender.TotalFare[i]=string2.substring(string2.indexOf("$", 0)+1, string2.length());
//System.out.println("SmsReceive.ParseData(GPRSDataSender.RouteInfo[i])"+GPRSDataSender.RouteInfo[i]);
//System.out.println("SmsReceive.ParseData(GPRSDataSender.TotalFare[i])"+GPRSDataSender.TotalFare[i]);
}
smsCanvas.isGprsClicked = true;
password pass = new password(smsCanvas);
smsCanvas.appState = smsCanvas.DETAILS_SUBMIT_SUCCESS;
}
/*
if(smsCanvas.isAskiingForRoutesSMS )
{
String string2;
GPRSDataSender.ChoiceID = new String[smsData.size()];
GPRSDataSender.RouteInfo = new String[smsData.size()];
GPRSDataSender.TotalFare = new String[smsData.size()];

GPRSDataSender.ChoiceID[0]="1";
String string3=smsData.elementAt(0).toString().substring(8, smsData.elementAt(0).toString().length());
GPRSDataSender.RouteInfo[0]=string3.substring(2, string3.indexOf("Rs"));
GPRSDataSender.TotalFare[0]=string3.substring(string3.indexOf("Rs", 3)+4,string3.length());
System.out.println("GPRSDataSender.TotalFare[0] - "+GPRSDataSender.TotalFare[0]);
for (int i = 1; i < smsData.size(); i++)
{
string2 = smsData.elementAt(i).toString();
GPRSDataSender.ChoiceID[i] = "" + (i + 1);

GPRSDataSender.RouteInfo[i]=string2.substring(2, string2.indexOf("Rs"));
GPRSDataSender.TotalFare[i]=string2.substring(string2.indexOf("Rs", 3)+4,string2.length());
myTotalFare = GPRSDataSender.TotalFare[password.select];
}
smsCanvas.isGprsClicked = true;
password pass = new password(smsCanvas);
smsCanvas.appState = smsCanvas.DETAILS_SUBMIT_SUCCESS;
}
*/
if(smsCanvas.isAskiingForTicketSMS)
{
String string2 = null;
for (int i = 0; i < smsData.size(); i++)
{
string2 = smsData.elementAt(i).toString();
}
BookedTicketHistory history = new BookedTicketHistory(smsCanvas.userInfoCanvas);
history.persistTheHistoryInformation();

GPRSDataSender.UTSNumber = getInfo("uts");
GPRSDataSender.Date = getInfo("DT");
GPRSDataSender.From_Station_Code=getInfo("FS");
GPRSDataSender.To_Station_Code=getInfo("TS");
GPRSDataSender.Validity_Password=getInfo("pw");
GPRSDataSender.TICKET_Validity=getInfo("val");
GPRSDataSender.RailwayRefNo = getInfo("RRF");


// GPRSDataSender.UTSNumber = getInfo("ticket no");
// GPRSDataSender.Date = getInfo("Date");
// GPRSDataSender.From_Station_Code=getInfo("From station");
// GPRSDataSender.To_Station_Code=getInfo("To Station");
// GPRSDataSender.Validity_Password=getInfo("pw");
// GPRSDataSender.TICKET_Validity="2 hours";
// GPRSDataSender.RailwayRefNo = getInfo("pw");
System.out.println("uts number - - "+GPRSDataSender.UTSNumber);
// System.out.println("date - - "+GPRSDataSender.Date);

//GPRSDataSender.RailwayRefNo =

smsCanvas.appState = smsCanvas.TICKET_TAKEN_STATE;
}
}
else
{
totalSMS = string.substring(1,string.length());
smsCanvas.appState = smsCanvas.SMS_ERROR_SCREEN_STATE11;
}
}

public void notifyIncomingMessage(MessageConnection arg0)
{
// TODO Auto-generated method stub
if (thread == null)
{
thread = new Thread(this);
thread.start();
}
}

}
then you can parse the sms,
In case of query write here,


Thanks

R a j - The K e r n e l
Reply With Quote

#5 Old Re: illegal unicode escape in j2me when i splite string... - 2009-01-16, 13:18

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
Quote:
Originally Posted by chaoraksa View Post
And when i call that Method to use like this: String[] Test=split("\u1780\u17B6\u1780\u17B7","\u");

and then i got an error message like this ( Illegal Unicode Ecapse ).
It's complaining about "\u". You can't have a string literal like that.

Remember that your first string ("\u1780\u17B6\u1780\u17B7") does not contain any "\u" sequences.

For example: if the string literal is "\u0041\u0042\u0043", the actual string is "ABC". The unicode escapes (\u) are converted to the actual characters before the compiler sees anything. The Java compiler has a kind of "unicode preprocessor" that expands all the characters in the source code to unicode. This "preprocessor" is complaining about "\u", which is can't expand.

If you want a string that contains a backslash followed by a lower-case "u", then you need to escape the backslash: "\\u".

Try:

Code:
String[] Test = split("\\u1780\\u17B6\\u1780\\u17B7", "\\u");
Cheers,
Graham.
Reply With Quote

#6 Old Thumbs up Re: illegal unicode escape in j2me when i splite string... - 2009-01-17, 05:11

Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
Send a message via Skype™ to raj_J2ME
raj_J2ME's Avatar
raj_J2ME
Offline
Forum Nokia Champion
Hi,
What grahamhughes have written over here, is the correct indeed,

I guess you want to split the string from the \u,as a separator .
why do not you pass any thing else like ~ and make the string like that,


Thanks

R a j - The K e r n e l
Reply With Quote

#7 Old Re: illegal unicode escape in j2me when i splite string... - 2009-01-17, 07:26

Join Date: Dec 2008
Posts: 122
chaoraksa
Offline
Regular Contributor
Thanks!
It is correct. Let me present my project that i want to do. I need to build one sms system in my language(KHMER) using J2ME. The reason i use "\u" as separator because i think when sms receive like that string(\u1780\u1781).Am i correct? I need to custom my own Font too and English Font. I still wonder that if i can't access the inbox of the system sms, and all sms will in my system right? and what about other setting of Message like(Msg Center, Delivery Reports, etc). What should i do?
Reply With Quote

#8 Old Thumbs up Re: illegal unicode escape in j2me when i splite string... - 2009-01-17, 07:56

Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
Send a message via Skype™ to raj_J2ME
raj_J2ME's Avatar
raj_J2ME
Offline
Forum Nokia Champion
Quote:
Originally Posted by chaoraksa View Post
Thanks!
It is correct. Let me present my project that i want to do. I need to build one sms system in my language(KHMER) using J2ME. The reason i use "\u" as separator because i think when sms receive like that string(\u1780\u1781).Am i correct? I need to custom my own Font too and English Font. I still wonder that if i can't access the inbox of the system sms, and all sms will in my system right? and what about other setting of Message like(Msg Center, Delivery Reports, etc). What should i do?

Hey,
Let me just talk about the sms string you are receiving from the smsc.Well tell me from where you are receiving the SMS ---- from SMSC,correct...
So ask to the the guys who are working on the server/SMSC end..they will just send the SMS in the format which suites you,
Then ask these people to send "~" as separator,

Well this is just a guess and a solution,.might be it does't suits to you,
Tell me if this idea can work for you,


Thanks

R a j - The K e r n e l
Reply With Quote

#9 Old Re: illegal unicode escape in j2me when i splite string... - 2009-01-17, 10:00

Join Date: Dec 2008
Posts: 122
chaoraksa
Offline
Regular Contributor
Yes, great idea but Unicode format is "\u" before the code number right?
Reply With Quote

#10 Old Thumbs up Re: illegal unicode escape in j2me when i splite string... - 2009-01-17, 10:10

Join Date: Mar 2008
Posts: 2,161
Location: The Capital of I N D I A
Send a message via Skype™ to raj_J2ME
raj_J2ME's Avatar
raj_J2ME
Offline
Forum Nokia Champion
Hi,

What is the total sms,I mean format..

what Grahm suggest,you can probably not use this operator.

Please post more informations about the flow of the application,


Thanks

R a j - The K e r n e l
Reply With Quote

#11 Old Re: illegal unicode escape in j2me when i splite string... - 2009-01-17, 12:40

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
The message will not contain "\u" sequences. These exist only in source code.

All characters are unicode, so it doesn't matter what the character is.

Unicode escapes are processed by the compiler. Writing:

Code:
"\u0041"
is identical to writing:

Code:
"A"
Both are strings of exactly one character, an upper-case Latin A.

Let's take your example:

Code:
String s = "\u1780\u17B6\u1780\u17B7";
char[] ch = s.toCharArray();
for (int i = 0; i < ch.length; i++) {
    System.out.println(Integer.toHexString((int)(ch[i]));
}
will print:

Code:
1780
17b6
1780
17b7
Your string contains only four characters, no "\", no "u".

Don't worry about the issue of handling unicode... Java does it all for you.

Cheers,
Graham.
Reply With Quote

#12 Old Re: illegal unicode escape in j2me when i splite string... - 2009-01-18, 18:53

Join Date: Dec 2008
Posts: 122
chaoraksa
Offline
Regular Contributor
hi!
My flow of this project have two things. First, i try to send sms in Unicode format from server using my Local Font(i custom font using Image) and display it in my phone. Second is from phone to phone by using my app.

I agree you Grahm but i custom my own language font map with that unicode code to display charactor​ in my cavas in j2me. Any recommand or suggestion please.

thanks you all.
Last edited by chaoraksa : 2009-01-18 at 19:02.
Reply With Quote

#13 Old Re: illegal unicode escape in j2me when i splite string... - 2009-01-18, 21:08

Join Date: Jun 2003
Posts: 4,325
Location: Cheshire, UK
grahamhughes's Avatar
grahamhughes
Offline
Forum Nokia Champion
Your problem with handling "unicode characters" is a red herring. All characters are unicode. It doesn't matter what the language is.

I've posted some sample source code for custom fonts in response to your other post.

Cheers,
Graham.
Reply With Quote

#14 Old Re: illegal unicode escape in j2me when i splite string... - 2009-01-19, 06:38

Join Date: Dec 2008
Posts: 122
chaoraksa
Offline
Regular Contributor
Hmmm!
That custom font is great. My language have foot, head, between sign and they are not in the same size. Could you please send the full source of that custom font to me, bec i'm not clear about the image.

Thanks
Reply With Quote

#15 Old Re: illegal unicode escape in j2me when i splite string... - 2009-01-20, 20:18

Join Date: Dec 2008
Posts: 122
chaoraksa
Offline
Regular Contributor
Please!!!
See this link http://www.unicode.org/charts/PDF/U1780.pdf and give me recommand for custom that font. And one more question i want to ask is related to Sms. When i send using this code:

public void run() {
try {

//construct sms URI with the phone number
String addr = "sms://" + this.phone + ":50000";

//open message connection with Connector class
MessageConnection conn = (MessageConnection) Connector.open(addr);

//construct TextMessage object
TextMessage msg =
(TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE);

//set the message
msg.setPayloadText("SMS Demo to " + text );

//sends the message
conn.send(msg);

//IllegalArgumentException happens when illegal phone number entered
} catch (IllegalArgumentException iae) {
//do something

//catch remaining Exception
} catch (Exception e) {
//do something
}
}
}

I got result like this

@MS Demo to Hi

I wonder why it have @ sign before it. When i send with no port number it normal. I really need you help.

thanks
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending Binary Messages on 3410 phone using J2ME affinitystudios Mobile Java General 3 2008-09-23 11:58
How can the WAP browser communicate to J2ME application? hbfornies Mobile Java General 20 2007-03-02 17:32
Nokia J2ME Unicode Escaping shangab Mobile Java Tools & SDKs 1 2005-03-19 18:59
J2ME Polish Version 1.0 RC6 enough Mobile Java General 1 2004-07-20 12:25
Illegal Operation using J2ME S60 MIDP Concept SDK ak37 Mobile Java Tools & SDKs 1 1970-01-01 02:00

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia