代码如下:// SendMessage.java - Sample application.
//
// This application shows you the basic procedure for sending messages.
// You will find how to send synchronous and asynchronous messages.
//
// For asynchronous dispatch, the example application sets a callback
// notification, to see what's happened with messages.
import org.smslib.IOutboundMessageNotification;
import org.smslib.Library;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.Message.MessageEncodings;
import org.smslib.modem.SerialModemGateway;public class SendMessage
{
public void doIt() throws Exception
{
   Service srv;
   OutboundMessage msg;
   OutboundNotification outboundNotification = new OutboundNotification();
   System.out.println("Example: Send message from a serial gsm modem.");
   System.out.println(Library.getLibraryDescription());
   System.out.println("Version: " + Library.getLibraryVersion());
   srv = new Service();
  
   SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM1", 9600, "wavecom", "1111");
   gateway.setInbound(true);
   gateway.setOutbound(true);
   gateway.setSimPin("0000");
   //gateway.setOutboundNotification(outboundNotification);
   srv.addGateway(gateway);
   srv.startService();
   System.out.println("Modem Information:");
   System.out.println(" Manufacturer: " + gateway.getManufacturer());
   System.out.println(" Model: " + gateway.getModel());
   System.out.println(" Serial No: " + gateway.getSerialNo());
   System.out.println(" SIM IMSI: " + gateway.getImsi());
   System.out.println(" Signal Level: " + gateway.getSignalLevel() + "%");
   System.out.println(" Battery Level: " + gateway.getBatteryLevel() + "%");
   System.out.println();
   // Send a message synchronously.
  
   msg = new OutboundMessage("15210121770", "这个是用java发的中文短信!");//手机号码,和短信内容
   msg.setEncoding(MessageEncodings.ENCUCS2);//这句话是发中文短信必须的
   srv.sendMessage(msg);
   System.out.println(msg);
   System.out.println("Now Sleeping - Hit <enter> to terminate.");
   System.in.read();
   srv.stopService();
}public class OutboundNotification implements IOutboundMessageNotification
{
   public void process(String gatewayId, OutboundMessage msg)
   {
    System.out.println("Outbound handler called from Gateway: " + gatewayId);
    System.out.println(msg);
   }
}public static void main(String args[])
{
   SendMessage app = new SendMessage();
   try
   {
    app.doIt();
   }
   catch (Exception e)
   {
    e.printStackTrace();
   }
}
}报错信息如下:
Example: Send message from a serial gsm modem.
SMSLib: A Java API library for sending and receiving SMS via a GSM modem
or other supported gateways.
Web Site: http://smslib.org
This software is distributed under the terms of the Apache v2.0 License.
Version: 3.3.0-b2
org.smslib.GatewayException: Comm library exception: java.lang.reflect.InvocationTargetException
JDK_HOME的环境配置已经配好。但还是出现上面的错误,请大家帮忙!

解决方案 »

  1.   

    org.smslib.GatewayException: Comm library exception: java.lang.reflect.InvocationTargetException 这个只是提示方法反射调用错误,没有具体到哪个方法?你用com链接的话,看看端口号是否对的?波码率对吗?
      

  2.   

    需要加用户去uucp组。具体可参考:http://code.google.com/p/smslib/wiki/Installation
      

  3.   

    代码本身没有问题问题是你的commons-net-1.4.1.jar or comm.jar or rxtx.jar 没有加载进来我不知道你用的什么serial port的包 一般来说是comm.jar 这个东西是需要加载进来的用classpath搞进来 否则你是打不开端口的
      

  4.   


    现在是程序没有问题了,也能够打开端口了。但是出现了下面的问题。org.smslib.TimeoutException:  No response from device.
        at org.smslib.modem.AModemDriver$CharQueue.get(AModemDriver.java:503)
        at org.smslib.modem.AModemDriver.getResponse(AModemDriver.java:295)
        at org.smslib.modem.athandler.ATHandler.getSimStatus(ATHandler.java:132)
        at org.smslib.modem.AModemDriver.connect(AModemDriver.java:129)
        at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:185)
        at org.smslib.Service$1Starter.run(Service.java:257)
      

  5.   

    org.smslib.GatewayException: Comm library exception: java.lang.reflect.InvocationTargetException
    at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:93)
    at org.smslib.modem.AModemDriver.connect(AModemDriver.java:106)
    at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:111)
    at org.smslib.Service$1Starter.run(Service.java:227)
      

  6.   

    我也出现过这个问题。
    org.smslib.GatewayException: Comm library exception: java.lang.reflect.InvocationTargetException
    at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:93)
    at org.smslib.modem.AModemDriver.connect(AModemDriver.java:106)
    at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:111)
    at org.smslib.Service$1Starter.run(Service.java:227)
    环境也配置好了。