BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 12-01-2008, 07:44 AM   #1
JoelParker
New Member
 
Join Date: Aug 2008
Model: Curve
PIN: N/A
Carrier: T-Mobile
Posts: 13
Default I/O Exception Thrown when using Message Listener

Please Login to Remove!

This class was working great fro sending sms messages until I added a message listener, know it throws an IOException every time I start the thread. Any Ideas, how to fix this ?

Below is the class and the message listener:

Code:
private static final class SmsMessage
    {
        private String _address;
        private String _msg;

        public SmsMessage(String address, String msg)
        {
            _address = address;
            _msg = msg;
        }
       
        public Message toMessage(MessageConnection mc)
        {
            TextMessage m = (TextMessage)mc.newMessage(MessageConnection.TEXT_MESSAGE,"sms://" + _address);
            m.setPayloadText(_msg);
            return m;
        }
    } // SmsMessage
   
   private final class SendThread extends Thread
    {
        private static final int TIMEOUT = 500; // ms
        private Vector _msgs = new Vector(10); // Queue of 10
        private volatile boolean _start = false;

        // queue requests
        public synchronized void send(String address, String msg)
        {
            _start = true;
            _msgs.addElement(new SmsMessage(address, msg));
        }

        public synchronized void stop()
        {
            _stop = true;
            try {
                if ( _mc != null ){
                    _mc.close();
                }
            } // catch (IOException e ) {
                catch (Throwable t) {
                t.printStackTrace();
                System.exit(0);
            }
              
        }

        public void run()
        {
            try {
                //closed by the stop() method
                _mc = (MessageConnection)Connector.open("sms://");
               
                if (_mc != null)
                {
                    // set a listener to trap outgoing sms messages
                    _mc.setMessageListener(new OutboundSMSListener());
                }
                for(;;)
                {
                    while( !_start && !_stop)
                    {
                        try {
                            sleep(TIMEOUT);
                        } // catch (InterruptedException e) {
                            catch (Throwable t) {
                                t.printStackTrace();
                                System.exit(0);
                            }
                    }
                    if ( _stop )
                    {
                        return;
                    }
   
                    while(true)
                    {
                        try {
                            SmsMessage sms = null;
                            synchronized (this)
                            {
                                if ( !_msgs.isEmpty() )
                                {
                                    sms = (SmsMessage)_msgs.firstElement();
                                    // take it out of the queue once we sent it
                                    _msgs.removeElement(sms);
                                }
                                else
                                {
                                    _start = false;
                                    break;
                                }
                            }
                           
                            _mc.send(sms.toMessage(_mc));
   
                        } // catch (IOException e) {
                            catch (Throwable t) {
                                t.printStackTrace();
                                System.exit(0);
                        }
                    }
                }
            } // catch (IOException e)
              catch (Throwable t) {
                t.printStackTrace();
                System.exit(0);
              }
        }
    } // SendThread
   
    private static final class OutboundSMSListener implements OutboundMessageListener
    {
        public void notifyIncomingMessage(MessageConnection messageconnection)
        {
            // we don't care about incoming sms messages right now
        }
       
        public void notifyOutgoingMessage(Message message)
        {
            Dialog.alert("Detected An Outgoing SMS Event");
        }
    }
Offline  
Old 12-01-2008, 03:43 PM   #2
jonberry
Thumbs Must Hurt
 
Join Date: Apr 2005
Model: 950
Carrier: T-Mobile
Posts: 185
Default

Are you sure the IOException is coming when from the Listener?
Offline  
Old 12-02-2008, 03:04 PM   #3
Jebadiah
New Member
 
Join Date: Dec 2008
Model: 8700
PIN: N/A
Carrier: AT&T
Posts: 4
Default

Hey Joel, I am creating a similar application. I am not sure why you're getting an exception. I suggest debugging it on the device.

On another note, have you figured out how to store the sent message in the Sent folder?
Offline  
Old 02-10-2009, 01:04 AM   #4
aashu.jaidka
New Member
 
Join Date: Sep 2008
Model: 8800
PIN: N/A
Carrier: airtel
Posts: 4
Default

it should be like :
_mc = (MessageConnection)Connector.open("sms://:portnumber");
where portnumber is 0 or 6222
Offline  
Closed Thread



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


New In Box ATOS E-MI-AS-IR Proportional Amplifier picture

New In Box ATOS E-MI-AS-IR Proportional Amplifier

$302.12



BJ300 Plus BJ300Plus 3-30MHz Radio Power Amplifier +Fan FM 100W AM 200W SSB 300W picture

BJ300 Plus BJ300Plus 3-30MHz Radio Power Amplifier +Fan FM 100W AM 200W SSB 300W

$104.49



REXROTH INDRAMAT ECO-DRIVE DKC02.3-040-7-FW SERVO CONTROLLER *REFURB U.S. SELLER picture

REXROTH INDRAMAT ECO-DRIVE DKC02.3-040-7-FW SERVO CONTROLLER *REFURB U.S. SELLER

$575.00



BOGEN COMMUNICATION 30W Digital Switching Amp Horn Self-Amplified Speaker SAH30 picture

BOGEN COMMUNICATION 30W Digital Switching Amp Horn Self-Amplified Speaker SAH30

$129.99



KEYENCE LR-TB5000CL Laser Sensor with Built-in Amplifier picture

KEYENCE LR-TB5000CL Laser Sensor with Built-in Amplifier

$289.99



Toa ca-130 car amplifier 30w picture

Toa ca-130 car amplifier 30w

$17.99







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.