Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
iphone4life4
Posts: 6
Registered: ‎07-13-2013
My Device: curve 9320
Accepted Solution

Get error when sending sms. [I think it is a simple fix. but I a newbie]

package com.iphone4life4;

import net.rim.device.api.system.*;
import javax.microedition.io.*;
import java.io.*;
public class App extends Application
{
     private String addr = "15198887465";
     private String msg = "This is a test message.";
     private DatagramConnection _dc = null;
     private static String _openString = "sms://";
     public static void main(String[] args)
     {
          new App().enterEventDispatcher();
     }
     public App()
     {
          try {
               _dc = (DatagramConnection)Connector.open(_openString);
               msg.getBytes();
               Datagram d = _dc.newDatagram(_dc.getMaximumLength());
               d.setAddress("//" + addr);
               _dc.send(d);
          } catch ( IOException e) {}
          System.exit(0);
     }
}

 That is my code and the error i get is this:

Thread [SMS2D(319)id=191674368] (Suspended (exception ClassCastException))	
	Protocol.makeMessage(DatagramBase) line: 974	
	Transport.send(Datagram, DatagramAddressBase, IOProperties, DatagramStatusListener, int) line: 445	
	Transport(DatagramTransportBase).superSend(Datagram) line: 299	
	Protocol(DatagramConnectionBase).send(Datagram) line: 320	
	Protocol.send(Datagram) line: 418	
	App.<init>() line: 23	
	App.main(String[]) line: 14	

 Whats wrong?

Developer
developer_aman_arora
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10

Re: Get error when sending sms. [I think it is a simple fix. but I a newbie]

[ Edited ]

try like this

new Thread()
{
   public void run() 
   {
      try
      {
         _dc = (DatagramConnection)Connector.open(_openString + addr);
        // msg.getBytes();
         Datagram d = _dc.newDatagram(_dc.getMaximumLength());
      //   d.setAddress("//" + addr);
         d.setData(msg.getBytes(),0,msg.getBytes().length());
         _dc.send(d);
      } 
      catch ( IOException e) 
      {
      }
   }
}.start();

 see working or not

 

Hit Like if you got your answer:smileyhappy:

New Contributor
iphone4life4
Posts: 6
Registered: ‎07-13-2013
My Device: curve 9320

Re: Get error when sending sms. [I think it is a simple fix. but I a newbie]

If I put in the simulators phone number into "private String addr" will the simulator be able to get the text msg?
Developer
developer_aman_arora
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10

Re: Get error when sending sms. [I think it is a simple fix. but I a newbie]

noooooo
Developer
developer_aman_arora
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10

Re: Get error when sending sms. [I think it is a simple fix. but I a newbie]

you have to test on real device
New Contributor
iphone4life4
Posts: 6
Registered: ‎07-13-2013
My Device: curve 9320

Re: Get error when sending sms. [I think it is a simple fix. but I a newbie]

Okay, will get back to you shortly.
New Contributor
iphone4life4
Posts: 6
Registered: ‎07-13-2013
My Device: curve 9320

Re: Get error when sending sms. [I think it is a simple fix. but I a newbie]

Great thanks a lot it works. One last thing before I mark a solved do you know how I can get delivery confirmation and read? I want to know when the user has received the text.
Developer
developer_aman_arora
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10

Re: Get error when sending sms. [I think it is a simple fix. but I a newbie]

you can display message on your side, message send
Developer
developer_aman_arora
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10

Re: Get error when sending sms. [I think it is a simple fix. but I a newbie]

New Contributor
iphone4life4
Posts: 6
Registered: ‎07-13-2013
My Device: curve 9320

Re: Get error when sending sms. [I think it is a simple fix. but I a newbie]

ok thx