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


WIFI Audio Voice Recorder Live Real-Time Audio Thru App | Charger & 32GB SD Card picture

WIFI Audio Voice Recorder Live Real-Time Audio Thru App | Charger & 32GB SD Card

$129.00



NEW Mitsubishi A1SNMCA-8KE Memory Cassette picture

NEW Mitsubishi A1SNMCA-8KE Memory Cassette

$151.62



1PC NEW Memory card 2711-NM11 2711-NM11 SPOT STOCK picture

1PC NEW Memory card 2711-NM11 2711-NM11 SPOT STOCK

$367.22



Argolladora We R Memory Keepers Heidi Swapp Cinch Binding Machine 71050-9 by AC picture

Argolladora We R Memory Keepers Heidi Swapp Cinch Binding Machine 71050-9 by AC

$79.99



1PC New ABB ACS880-MU-ZCU-12/14 ZMU-02 Inverter Memory Card 1year waranty picture

1PC New ABB ACS880-MU-ZCU-12/14 ZMU-02 Inverter Memory Card 1year waranty

$84.46



New Sealed AB 2080-MEMBAK-RTC Memory Backup, Data Log, Recipe ,High Accuracy RTC picture

New Sealed AB 2080-MEMBAK-RTC Memory Backup, Data Log, Recipe ,High Accuracy RTC

$281.95







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