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


MMA Memory Module  picture

MMA Memory Module

$150.00



New Factory Sealed AB 1756-L61 SER B ControlLogix 2MB Memory Controller 1756L61 picture

New Factory Sealed AB 1756-L61 SER B ControlLogix 2MB Memory Controller 1756L61

$304.69



2711-NM11 PCMCIA Linear Flash Memory Card 256KB Fast Shipping AB 2711NM11 picture

2711-NM11 PCMCIA Linear Flash Memory Card 256KB Fast Shipping AB 2711NM11

$350.66



NEW Original Allen Bradley 2080-MEMBAK-RTC Memory Module With RTC Plug-In picture

NEW Original Allen Bradley 2080-MEMBAK-RTC Memory Module With RTC Plug-In

$291.75



AVNET ULTRAZED SOM ZYNQ ULTRASCALE+ XCZU3EG SYSTEM ON MODULE -  picture

AVNET ULTRAZED SOM ZYNQ ULTRASCALE+ XCZU3EG SYSTEM ON MODULE -

$98.67



Serta Big and Tall Commercial Office Chair Memory Foam 350 Lb Capacity Black NEW picture

Serta Big and Tall Commercial Office Chair Memory Foam 350 Lb Capacity Black NEW

$179.99







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