anyone could help me with extracting phone number from a txt file. I got a lot of txt files in a folder titled with an id. if user input a certain id, the midlet will read the file title as id.txt, and read the string as the phone number in the file then send message to that string.(for example, if input is 1, will read 1.txt return string 123467890, then send message to 1234567890).
But now my problem is that I can read the txt file by the code:
**public String Loadnumber(String fileName){
String str="";
try{
FileConnection fc =(FileConnection)Connector.open("file://localhost/root1/res/number/"+fileName);
if(!fc.exists()){
hrow new IOException("File does not exist");
}
InputStream is=fc.openInputStream();
byte b[]=new byte[1024];
int length = is.read(b,0,1024);
str = new String (b,0,length);
}catch(Exception e ){
}
return str;
}****
Then I inserted the return string of the Loadnumber function to the phone number address box:
**String number= new String(Loadnumber(id+".txt"));
destinationAddressBox.insert(number,0);**
The destinationAddressBox is the phone number box, when I enter the id and press the button it will display this box, I declared it as:
**destinationAddressBox = new TextBox("phone number", number,1024,TextField.PHONENUMBER);
destinationAddressBox.addCommand(okCommand);
destinationAddressBox.setCommandListener(this);**
But when I run it and after press the ok button in the box for entering id, it will not prompt the address box and will give me the error message as:
**java.lang.IllegalArgumentException
at javax.microedition.lcdui.TextField.insert(+55)
at javax.microedition.lcdui.TextField.insert(+14)
at javax.microedition.lcdui.TextBox.insert(+9)
at example.sms.SMSSend.commandAction(+72)
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(+186)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+57)**
But if I changed the textfield as TextField.ANY instead of TextField.PHONENUMBER, it will prompt the address box and show the phone number in my txt file,but it will not send the message and give me the error messge:
**java.lang.IllegalArgumentException: Host format
at com.sun.midp.io.j2me.sms.Protocol.openPrimInternal(+198)
at com.sun.midp.io.j2me.sms.Protocol.openPrim(+8)
at javax.microedition.io.Connector.openPrim(+299)
at javax.microedition.io.Connector.open(+15)
at javax.microedition.io.Connector.open(+6)
at javax.microedition.io.Connector.open(+5)
at example.sms.SMSSend.run(+100)**
I guess the textfield matters a lot. How could I balance that? Thank you so much in advance!