1

I installed library smslib in my windows machine. I followed all the instructions at the website smslib.org for library setup. But when I'm trying to run the SendMessage example got an error.

    package examples.modem;

    import org.smslib.AGateway;
    import org.smslib.IOutboundMessageNotification;
    import org.smslib.Library;
    import org.smslib.OutboundMessage;
    import org.smslib.Service;
    import org.smslib.modem.SerialModemGateway;

    public class SendMessage
    {
        public void doIt() throws Exception
        {

            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());
            SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM12", 115200, "Huawei", "E303");
            gateway.setInbound(true);
            gateway.setOutbound(true);
            gateway.setSimPin("0000");
            // Explicit SMSC address set is required for some modems.
            // Below is for VODAFONE GREECE - be sure to set your own!
            gateway.setSmscNumber("+xxxxxxxxxxx");
            Service.getInstance().setOutboundMessageNotification(outboundNotification);
            Service.getInstance().addGateway(gateway);
            Service.getInstance().startService();
            System.out.println();
            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() + " dBm");
            System.out.println("  Battery Level: " + gateway.getBatteryLevel() + "%");
            System.out.println();
            // Send a message synchronously.
            OutboundMessage msg = new OutboundMessage("xxxxxxxxx", "Hello from SMSLib!");
            Service.getInstance().sendMessage(msg);
            System.out.println(msg);
            // Or, send out a WAP SI message.
            //OutboundWapSIMessage wapMsg = new OutboundWapSIMessage("xxxxxxxx",  new URL("http://www.smslib.org/"), "Visit SMSLib now!");
            //Service.getInstance().sendMessage(wapMsg);
            //System.out.println(wapMsg);
            // You can also queue some asynchronous messages to see how the callbacks
            // are called...
            //msg = new OutboundMessage("xxxxxxxxxxx", "Wrong number!");
            //srv.queueMessage(msg, gateway.getGatewayId());
            //msg = new OutboundMessage("308888888888", "Wrong number!");
            //srv.queueMessage(msg, gateway.getGatewayId());
            System.out.println("Now Sleeping - Hit <enter> to terminate.");
            System.in.read();
            Service.getInstance().stopService();
        }

          public class OutboundNotification implements IOutboundMessageNotification
    {
        public void process(AGateway gateway, OutboundMessage msg)
        {
            System.out.println("Outbound handler called from Gateway: " + gateway.getGatewayId());
            System.out.println(msg);
        }
    }

    public static void main(String args[])
    {
        SendMessage app = new SendMessage();
        try
        {
            app.doIt();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

error:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
The method getInstance() is undefined for the type Service
The method getInstance() is undefined for the type Service
The method getInstance() is undefined for the type Service
The method getInstance() is undefined for the type Service
The method getInstance() is undefined for the type Service

at examples.modem.SendMessage.doIt(SendMessage.java:34)
at examples.modem.SendMessage.main(SendMessage.java:79)

Can any one please help me with this?

  • You haven't added the smslib to your classpath did you? – André Dec 18 '14 at 11:00
  • Nope I've added, I checked it again – Kaveen Kumarasinghe Dec 18 '14 at 11:18
  • Well, "Unresolved compilation problems" means that you tried run a java program complied with jdt compiler, that has erros. It can't find the method getInstance(). Check if you have a valid jar, check if the version you have does have that method, check if the added jar is the right one. I'm pretty sure is just a classpath issue. – André Dec 18 '14 at 11:29
  • Thanks, I used smslib-3.5.0 and that error was gone but when running raised another exception: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError--- – Kaveen Kumarasinghe Dec 18 '14 at 11:57
  • That isn't related to smslib, You have to choose a logging framework. you're saying to log4j that you will use slf4j, and you're saying to slf4j that you're going to use log4j. Remove one of those frameworks and see if works. Can't say which one is needed. – André Dec 18 '14 at 12:03
  • If you fixed your issue, it's a good practice to answer it yourself with the solution :) – André Dec 19 '14 at 10:08

1 Answers1

0

checklist :-

  • add javax.comm.properties,
  • Win32.dll file (these you need to talk to your modem)
  • smslib jar
  • Make sure you have a compatible modem. The android smartphones dont work. you either need some specific old school models with inbuilt modem or a usb-GSM modem.
  • Are there other classes in your package?
  • I've added javax.comm.properties in to JAVA_HOME\jre\lib\ext , win32.dll in to JAVA_HOME\jre\bin, smslib jar in to class path. But still same error – Kaveen Kumarasinghe Dec 18 '14 at 11:24