I have develop a
midlet for send a sms. I use the wma api and when i
start the app on the phone, i get a exception:
cannot create class in system package
when i use the SMS api with the address:
com.nokia.sms:// and number
i get a nullpointerexception.
here my code:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.Connector;
import javax.wireless.messaging.*;
public class WmaSend extends MIDlet implements
CommandListener
{
Display display;
Form mainForm;
MessageConnection conn;
TextMessage tmsg;
Command sendCmd = new Command("Send",
Command.SCREEN, 1);
Command exitCmd = new Command("Exit",
Command.EXIT, 1);
TextField address = new TextField("Address: ",
"NUMBER", 200, TextField.ANY);
ChoiceGroup typeSelect = new
ChoiceGroup("Messagetyp: ", Choice.EXCLUSIVE, new
String[] {"Text","Binary"}, null);
TextField port = new TextField("Port:", "", 5,
TextField.ANY);
TextField text = new TextField("Text:", "This is a
example SMS.", 160, TextField.ANY);
public WmaSend()
{
display = Display.getDisplay(this);
mainForm = new Form("WmaSend");
mainForm.append(address);
mainForm.append(port);
mainForm.append(typeSelect);
mainForm.append(text);
mainForm.addCommand(sendCmd);
mainForm.addCommand(exitCmd);
mainForm.setCommandListener(this);
}
public void commandAction(Command c, Displayable
d)
{
if(c == sendCmd)
{
try
{
String addr = "sms://" + address.getString() +
((port.getString().length() == 0) ? "" : ":" +
port.getString());
try {
conn =
(MessageConnection)Connector.open(addr);
}
catch (Exception ioe)
{
ioe.printStackTrace();
Alert alert = new Alert("IOError !");
alert.setString("SMS not send. IOError: " +
ioe.toString());
display.setCurrent(alert, mainForm);
}
if(typeSelect.getString(typeSelect.getSelectedIndex()).equals("Text"))
{
tmsg =
(TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE);
try {
tmsg.setPayloadText(text.getString());
tmsg =
(TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE);
}
catch (Exception e2)
{
Alert alert = new Alert("SendErroe !");
alert.setString("Sms not send. CreateError: " +
e2.toString()+ " "+conn.toString());
display.setCurrent(alert, mainForm);
}
try {
conn.send(tmsg);
conn.close();
}
catch (Exception e1)
{
Alert alert = new Alert("SendErroe !");
alert.setString("Sms not send. SendError: " +
e1.toString());
display.setCurrent(alert, mainForm);
}
}
else
if(typeSelect.getString(typeSelect.getSelectedIndex()).equals("Binary"))
{
BinaryMessage bmsg =
(BinaryMessage)conn.newMessage(MessageConnection.BINARY_MESSAGE);
bmsg.setPayloadData(text.getString().getBytes());
conn.send(bmsg);
conn.close();
}
Alert alert = new Alert("Suuccessful.");
alert.setString((typeSelect.getString(typeSelect.getSelectedIndex()).equals("Binary")
? "Binary" : "Text") + "-SMS sent to " + addr);
display.setCurrent(alert, mainForm);
}
catch (Exception e)
{
e.printStackTrace();
Alert alert = new Alert("Error !");
alert.setString("SMS hallo not send. Error: " +
e.toString());
display.setCurrent(alert, mainForm);
}
address.setString("");
port.setString("");
text.setString("");
}
else
{
notifyDestroyed();
}
}
public void startApp()
{
display.setCurrent(mainForm);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
}
where is the mistake?
thanks for halp
best regards
natrix

Reply With Quote

