BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/index.php)
-   Developer Forum (http://www.blackberryforums.com/forumdisplay.php?f=15)
-   -   Problem with SMS (http://www.blackberryforums.com/showthread.php?t=174157)

Chris Lee 02-04-2009 02:42 AM

Problem with SMS
 
When I used first sample source, It works well
But, Second source throws exception "_dc.send(d);" point
What wrong with this?


First Source
--------------------------------------------------------------------
import net.rim.device.api.system.*;
import javax.microedition.io.*;
import java.io.*;

public class SmsSample extends Application {
private static final int MAX_PHONE_NUMBER_LENGTH = 32;
// Members.
private String addr = "01029581234";
private String msg = "This is a test message.";
private DatagramConnection _dc = null;
private static String _openString = "sms://";

public static void main(String[] args) {

new SmsSample();
}

public SmsSample() {

try {
_dc = (DatagramConnection) Connector.open(_openString);
byte[] data = msg.getBytes();
Datagram d = _dc.newDatagram(_dc.getMaximumLength());
d.setAddress("//" + addr);
d.setData(data, 0, data.length);
_dc.send(d);
} catch (IOException e) {
}
System.exit(0);
}

}


Second source

--------------------------------------------------------------------

import java.io.IOException;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import javax.microedition.io.*;


public class SmsFinal extends UiApplication {
public static void main(String[] args) {
SmsFinal theApp = new SmsFinal();
theApp.enterEventDispatcher();
}

public SmsFinal() {
pushScreen(new SmsFinalScreen());
}

final class SmsFinalScreen extends MainScreen {

public SmsFinalScreen() {
super();
FieldChangeListener listener = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
String addr = "01029581234";
String msg = "This is a test message.";
DatagramConnection _dc = null;
try {
_dc = (DatagramConnection) Connector.open("sms://");
byte[] data = msg.getBytes();
Datagram d = _dc.newDatagram(_dc.getMaximumLength());
d.setAddress("//" + addr);
d.setData(data, 0, data.length);
_dc.send(d); //Exception Point
} catch (IOException e) {
}
}
};
ButtonField buttonField = new ButtonField("Button");
buttonField.setChangeListener(listener);
add(buttonField);
}
}
}

And how can I see the exception message on BlackBerry Device?
Thanks


All times are GMT -5. The time now is 06:50 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.